This is Unofficial EPICS BASE Doxygen Site
osdEnv.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Saskatchewan
3 * EPICS BASE is distributed subject to a Software License Agreement found
4 * in file LICENSE that is included with this distribution.
5 \*************************************************************************/
6 /* osdEnv.c */
7 /*
8  * Author: Eric Norum
9  * Date: May 7, 2001
10  *
11  * Routines to modify/display environment variables and EPICS parameters
12  *
13  */
14 
15 #include <string.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <ctype.h>
19 #include <errno.h>
20 
21 /*
22  * Starting in Mac OS X 10.5 (Leopard) shared libraries and
23  * bundles don't have direct access to environ (man environ).
24  */
25 #include <crt_externs.h>
26 #define environ (*_NSGetEnviron())
27 
28 #include "epicsStdio.h"
29 #include "envDefs.h"
30 #include "iocsh.h"
31 
32 /*
33  * Set the value of an environment variable
34  */
35 LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
36 {
37  if (!name) return;
38  iocshEnvClear(name);
39  setenv(name, value, 1);
40 }
41 
42 /*
43  * Unset an environment variable
44  */
45 
46 LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
47 {
48  iocshEnvClear(name);
49  unsetenv(name);
50 }
51 
52 /*
53  * Show the value of the specified, or all, environment variables
54  */
55 LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
56 {
57  if (name == NULL) {
58  extern char **environ;
59  char **sp;
60 
61  for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
62  printf ("%s\n", *sp);
63  }
64  else {
65  const char *cp = getenv (name);
66  if (cp == NULL)
67  printf ("%s is not an environment variable.\n", name);
68  else
69  printf ("%s=%s\n", name, cp);
70  }
71 }
Definition: link.h:174
void epicsStdCall iocshEnvClear(const char *name)
Definition: iocsh.cpp:1054
Routines to get and set EPICS environment parameters.
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsEnvShow(const char *name)
Print value of an environment variable, or all variables.
Definition: osdEnv.c:55
LIBCOM_API void epicsStdCall epicsEnvSet(const char *name, const char *value)
Set an environment variable&#39;s value.
Definition: osdEnv.c:35
#define environ
Definition: osdEnv.c:26
LIBCOM_API void epicsStdCall epicsEnvUnset(const char *name)
Clear the value of an environment variable.
Definition: osdEnv.c:46