LCOV - code coverage report
Current view: top level - src - sysutils.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2015-11-05 17:06:03 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* sysutils.c - System utilities
       2             :    Copyright (C) 2010 Free Software Foundation, Inc.
       3             : 
       4             :    This file is part of Assuan.
       5             : 
       6             :    Assuan is free software; you can redistribute it and/or modify it
       7             :    under the terms of the GNU Lesser General Public License as
       8             :    published by the Free Software Foundation; either version 2.1 of
       9             :    the License, or (at your option) any later version.
      10             : 
      11             :    Assuan is distributed in the hope that it will be useful, but
      12             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :    Lesser General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU Lesser General Public
      17             :    License along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #ifdef HAVE_CONFIG_H
      21             : #include <config.h>
      22             : #endif
      23             : #include <stdio.h>
      24             : #include <stdlib.h>
      25             : #include <string.h>
      26             : #include <stdarg.h>
      27             : #ifdef HAVE_W32_SYSTEM
      28             : # ifdef HAVE_WINSOCK2_H
      29             : #  include <winsock2.h>
      30             : # endif
      31             : # include <windows.h>
      32             : # ifdef HAVE_W32CE_SYSTEM
      33             : # include <winioctl.h>
      34             : # endif /*HAVE_W32CE_SYSTEM*/
      35             : #endif /*HAVE_W32_SYSTEM*/
      36             : 
      37             : #include "assuan-defs.h"
      38             : 
      39             : 
      40             : /* This is actually a dummy function to make sure that is module is
      41             :    not empty.  Some compilers barf on empty modules.  */
      42             : const char *
      43           1 : _assuan_sysutils_blurb (void)
      44             : {
      45             :   static const char blurb[] =
      46             :     "\n\n"
      47             :     "This is Libassuan " PACKAGE_VERSION " - The GnuPG IPC Library\n"
      48             :     "Copyright 2001-2013 Free Software Foundation, Inc.\n"
      49             :     "Copyright 2001-2014 g10 Code GmbH\n"
      50             :     "\n"
      51             :     "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n"
      52             :     "\n\n";
      53           1 :   return blurb;
      54             : }
      55             : 
      56             : 
      57             : /* Return a string from the Win32 Registry or NULL in case of error.
      58             :    The returned string is allocated using a plain malloc and thus the
      59             :    caller needs to call the standard free().  The string is looked up
      60             :    under HKEY_LOCAL_MACHINE.  */
      61             : #ifdef HAVE_W32CE_SYSTEM
      62             : static char *
      63             : w32_read_registry (const wchar_t *dir, const wchar_t *name)
      64             : {
      65             :   HKEY handle;
      66             :   DWORD n, nbytes;
      67             :   wchar_t *buffer = NULL;
      68             :   char *result = NULL;
      69             : 
      70             :   if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &handle))
      71             :     return NULL; /* No need for a RegClose, so return immediately. */
      72             : 
      73             :   nbytes = 1;
      74             :   if (RegQueryValueEx (handle, name, 0, NULL, NULL, &nbytes))
      75             :     goto out;
      76             :   buffer = malloc ((n=nbytes+2));
      77             :   if (!buffer)
      78             :     goto out;
      79             :   if (RegQueryValueEx (handle, name, 0, NULL, (PBYTE)buffer, &n))
      80             :     {
      81             :       free (buffer);
      82             :       buffer = NULL;
      83             :       goto out;
      84             :     }
      85             : 
      86             :   n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, NULL, 0, NULL, NULL);
      87             :   if (n < 0 || (n+1) <= 0)
      88             :     goto out;
      89             :   result = malloc (n+1);
      90             :   if (!result)
      91             :     goto out;
      92             :   n = WideCharToMultiByte (CP_UTF8, 0, buffer, nbytes, result, n, NULL, NULL);
      93             :   if (n < 0)
      94             :     {
      95             :       free (result);
      96             :       result = NULL;
      97             :       goto out;
      98             :     }
      99             :   result[n] = 0;
     100             : 
     101             :  out:
     102             :   free (buffer);
     103             :   RegCloseKey (handle);
     104             :   return result;
     105             : }
     106             : #endif /*HAVE_W32CE_SYSTEM*/
     107             : 
     108             : 
     109             : 
     110             : #ifdef HAVE_W32CE_SYSTEM
     111             : /* Replacement for getenv which takes care of the our use of getenv.
     112             :    The code is not thread safe but we expect it to work in all cases
     113             :    because it is called for the first time early enough.  */
     114             : char *
     115             : _assuan_getenv (const char *name)
     116             : {
     117             :   static int initialized;
     118             :   static char *val_debug;
     119             :   static char *val_full_logging;
     120             : 
     121             :   if (!initialized)
     122             :     {
     123             :       val_debug = w32_read_registry (L"\\Software\\GNU\\libassuan",
     124             :                                      L"debug");
     125             :       val_full_logging = w32_read_registry (L"\\Software\\GNU\\libassuan",
     126             :                                             L"full_logging");
     127             :       initialized = 1;
     128             :     }
     129             : 
     130             : 
     131             :   if (!strcmp (name, "ASSUAN_DEBUG"))
     132             :     return val_debug;
     133             :   else if (!strcmp (name, "ASSUAN_FULL_LOGGING"))
     134             :     return val_full_logging;
     135             :   else
     136             :     return NULL;
     137             : }
     138             : #endif /*HAVE_W32CE_SYSTEM*/

Generated by: LCOV version 1.11