diff --git a/src/libCom/osi/os/Darwin/osdEnv.c b/src/libCom/osi/os/Darwin/osdEnv.c new file mode 100644 index 000000000..643986204 --- /dev/null +++ b/src/libCom/osi/os/Darwin/osdEnv.c @@ -0,0 +1,86 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Saskatchewan +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* osdEnv.c */ +/* + * $Id$ + * + * Author: Eric Norum + * Date: May 7, 2001 + * + * Routines to modify/display environment variables and EPICS parameters + * + */ + +#include +#include +#include +#include +#include + +/* + * Starting in Mac OS X 10.5 (Leopard) shared libraries and + * bundles don't have direct access to environ (man environ). + */ +#ifdef __AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER +# include +# define environ (*_NSGetEnviron()) +#endif + +#define epicsExportSharedSymbols +#include +#include +#include +#include +#include +#include "epicsFindSymbol.h" + +/* + * Set the value of an environment variable + * Leaks memory, but the assumption is that this routine won't be + * called often enough for the leak to be a problem. + */ +epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *value) +{ + char *cp; + + cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet"); + strcpy (cp, name); + strcat (cp, "="); + strcat (cp, value); + if (putenv (cp) < 0) { + errPrintf( + -1L, + __FILE__, + __LINE__, + "Failed to set environment parameter \"%s\" to \"%s\": %s\n", + name, + value, + strerror (errno)); + free (cp); + } +} + +/* + * Show the value of the specified, or all, environment variables + */ +epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name) +{ + if (name == NULL) { + extern char **environ; + char **sp; + + for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++) + printf ("%s\n", *sp); + } + else { + const char *cp = getenv (name); + if (cp == NULL) + printf ("%s is not an environment variable.\n", name); + else + printf ("%s=%s\n", name, cp); + } +}