LCOV - code coverage report
Current view: top level - src - get-env.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 7 8 87.5 %
Date: 2016-09-12 12:35:26 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* get_env.c - A getenv() replacement.
       2             :    Copyright (C) 2003, 2004 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             : 
       6             :    GPGME 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             :    GPGME 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, write to the Free Software
      18             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      19             :    02111-1307, USA.  */
      20             : 
      21             : #if HAVE_CONFIG_H
      22             : #include <config.h>
      23             : #endif
      24             : #include <stdlib.h>
      25             : #include <errno.h>
      26             : #include <string.h>
      27             : 
      28             : #include "util.h"
      29             : 
      30             : 
      31             : #if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R)
      32             : /* We prefer using getenv() if it is thread-safe.  */
      33             : 
      34             : /* Retrieve the environment variable NAME and return a copy of it in a
      35             :    malloc()'ed buffer in *VALUE.  If the environment variable is not
      36             :    set, return NULL in *VALUE.  */
      37             : gpgme_error_t
      38         615 : _gpgme_getenv (const char *name, char **value)
      39             : {
      40             :   char *env_value;
      41             : 
      42         615 :   env_value = getenv (name);
      43         615 :   if (!env_value)
      44          59 :     *value = NULL;
      45             :   else
      46             :     {
      47         556 :       *value = strdup (env_value);
      48         556 :       if (!*value)
      49           0 :         return gpg_error_from_syserror ();
      50             :     }
      51         615 :   return 0;
      52             : }
      53             : 
      54             : #else
      55             : 
      56             : /* FIXME: Implement this when we have the specification for it.  */
      57             : #error Use of getenv_r not implemented.
      58             : 
      59             : #endif

Generated by: LCOV version 1.11