diff options
| author | NIIBE Yutaka <[email protected]> | 2018-01-29 02:45:33 +0000 | 
|---|---|---|
| committer | NIIBE Yutaka <[email protected]> | 2018-01-29 02:45:33 +0000 | 
| commit | 37d62e9d0f685c257fdb5f303e60ff01f8a36a2f (patch) | |
| tree | c5f16cd98602b107efa4bbf59ad844bf152d005b | |
| parent | Post release updates. (diff) | |
| download | gpgme-37d62e9d0f685c257fdb5f303e60ff01f8a36a2f.tar.gz gpgme-37d62e9d0f685c257fdb5f303e60ff01f8a36a2f.zip | |
core: Implement _gpgme_getenv for NetBSD.
* src/get-env.c [HAVE_GETENV_R] (_gpgme_getenv): New.
--
GnuPG-bug-id: 3056
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to '')
| -rw-r--r-- | src/get-env.c | 41 | 
1 files changed, 40 insertions, 1 deletions
| diff --git a/src/get-env.c b/src/get-env.c index 57fd4196..9e2df682 100644 --- a/src/get-env.c +++ b/src/get-env.c @@ -28,7 +28,7 @@  #include "util.h" -#if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R) +#if defined(HAVE_THREAD_SAFE_GETENV)  /* We prefer using getenv() if it is thread-safe.  */  /* Retrieve the environment variable NAME and return a copy of it in a @@ -50,7 +50,46 @@ _gpgme_getenv (const char *name, char **value)      }    return 0;  } +#elif defined (HAVE_GETENV_R) +#define INITIAL_GETENV_SIZE 32 +gpgme_error_t +_gpgme_getenv (const char *name, char **value) +{ +  size_t len = INITIAL_GETENV_SIZE; +  char *env_value; + +  env_value = malloc (len); + +  while (1) +    { +      *value = env_value; +      if (!env_value) +        return gpg_error_from_syserror (); + +      if (getenv_r (name, env_value, len) == 0) +        break; + +      if (errno == ERANGE) +        { +          len *= 2; +          env_value = realloc (env_value, len); +        } +      else +        { +          int saved = errno; + +          free (env_value); +          *value = NULL; +          if (errno == ENOENT) +            return 0; +          else +          return gpg_error_from_errno (saved); +        } +    } + +  return 0; +}  #else  /* FIXME: Implement this when we have the specification for it.  */ | 
