|
Packit |
d7e8d0 |
/* get_env.c - A getenv() replacement.
|
|
Packit |
d7e8d0 |
Copyright (C) 2003, 2004 g10 Code GmbH
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
This file is part of GPGME.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGME is free software; you can redistribute it and/or modify it
|
|
Packit |
d7e8d0 |
under the terms of the GNU Lesser General Public License as
|
|
Packit |
d7e8d0 |
published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
d7e8d0 |
the License, or (at your option) any later version.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
GPGME is distributed in the hope that it will be useful, but
|
|
Packit |
d7e8d0 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
d7e8d0 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
d7e8d0 |
Lesser General Public License for more details.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
d7e8d0 |
License along with this program; if not, write to the Free Software
|
|
Packit |
d7e8d0 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
Packit |
d7e8d0 |
02111-1307, USA. */
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#if HAVE_CONFIG_H
|
|
Packit |
d7e8d0 |
#include <config.h>
|
|
Packit |
d7e8d0 |
#endif
|
|
Packit |
d7e8d0 |
#include <stdlib.h>
|
|
Packit |
d7e8d0 |
#include <errno.h>
|
|
Packit |
d7e8d0 |
#include <string.h>
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#include "util.h"
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#if defined(HAVE_THREAD_SAFE_GETENV) || !defined (HAVE_GETENV_R)
|
|
Packit |
d7e8d0 |
/* We prefer using getenv() if it is thread-safe. */
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
/* Retrieve the environment variable NAME and return a copy of it in a
|
|
Packit |
d7e8d0 |
malloc()'ed buffer in *VALUE. If the environment variable is not
|
|
Packit |
d7e8d0 |
set, return NULL in *VALUE. */
|
|
Packit |
d7e8d0 |
gpgme_error_t
|
|
Packit |
d7e8d0 |
_gpgme_getenv (const char *name, char **value)
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
char *env_value;
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
env_value = getenv (name);
|
|
Packit |
d7e8d0 |
if (!env_value)
|
|
Packit |
d7e8d0 |
*value = NULL;
|
|
Packit |
d7e8d0 |
else
|
|
Packit |
d7e8d0 |
{
|
|
Packit |
d7e8d0 |
*value = strdup (env_value);
|
|
Packit |
d7e8d0 |
if (!*value)
|
|
Packit |
d7e8d0 |
return gpg_error_from_syserror ();
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
return 0;
|
|
Packit |
d7e8d0 |
}
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#else
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
/* FIXME: Implement this when we have the specification for it. */
|
|
Packit |
d7e8d0 |
#error Use of getenv_r not implemented.
|
|
Packit |
d7e8d0 |
|
|
Packit |
d7e8d0 |
#endif
|