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 <gniibe@fsij.org>
This commit is contained in:
parent
7da01c7352
commit
37d62e9d0f
@ -28,7 +28,7 @@
|
|||||||
#include "util.h"
|
#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. */
|
/* We prefer using getenv() if it is thread-safe. */
|
||||||
|
|
||||||
/* Retrieve the environment variable NAME and return a copy of it in a
|
/* 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;
|
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
|
#else
|
||||||
|
|
||||||
/* FIXME: Implement this when we have the specification for it. */
|
/* FIXME: Implement this when we have the specification for it. */
|
||||||
|
Loading…
Reference in New Issue
Block a user