This is Unofficial EPICS BASE Doxygen Site
osdEnv.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "epicsStdio.h"
#include "errlog.h"
#include "cantProceed.h"
#include "envDefs.h"
#include "osiUnistd.h"
#include "epicsFindSymbol.h"
#include "iocsh.h"
+ Include dependency graph for osdEnv.c:

Go to the source code of this file.

Functions

LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
 Set an environment variable's value. More...
 
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
 Clear the value of an environment variable. More...
 
LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
 Print value of an environment variable, or all variables. More...
 

Function Documentation

LIBCOM_API void epicsStdCall epicsEnvSet ( const char *  name,
const char *  value 
)

Set an environment variable's value.

The setenv() routine is not available on all operating systems. This routine provides a portable alternative for all EPICS targets.

Parameters
nameEnvironment variable name.
valueNew value for environment variable.

Definition at line 34 of file osdEnv.c.

35 {
36  char *cp;
37 
38  iocshEnvClear(name);
39 
40  cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
41  strcpy (cp, name);
42  strcat (cp, "=");
43  strcat (cp, value);
44  if (putenv (cp) < 0) {
45  errPrintf(
46  -1L,
47  __FILE__,
48  __LINE__,
49  "Failed to set environment parameter \"%s\" to \"%s\": %s\n",
50  name,
51  value,
52  strerror (errno));
53  free (cp);
54  }
55 }
Definition: link.h:174
void epicsStdCall iocshEnvClear(const char *name)
Definition: iocsh.cpp:1054
void errPrintf(long status, const char *pFileName, int lineno, const char *pformat,...)
Definition: errlog.c:383
int putenv(char *)
LIBCOM_API void * mallocMustSucceed(size_t size, const char *msg)
A malloc() that never returns NULL.
Definition: cantProceed.c:38
LIBCOM_API void epicsStdCall epicsEnvShow ( const char *  name)

Print value of an environment variable, or all variables.

Parameters
nameEnvironment variable name, or NULL to show all.

Definition at line 72 of file osdEnv.c.

73 {
74  if (name == NULL) {
75  extern char **environ;
76  char **sp;
77 
78  for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
79  printf ("%s\n", *sp);
80  }
81  else {
82  const char *cp = getenv (name);
83  if (cp == NULL)
84  printf ("%s is not an environment variable.\n", name);
85  else
86  printf ("%s=%s\n", name, cp);
87  }
88 }
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
#define environ
Definition: osdEnv.c:26
LIBCOM_API void epicsStdCall epicsEnvUnset ( const char *  name)

Clear the value of an environment variable.

Parameters
nameEnvironment variable name.

Definition at line 62 of file osdEnv.c.

63 {
64  iocshEnvClear(name);
65  if (getenv(name) != NULL)
66  epicsEnvSet((char*)name, "");
67 }
void epicsStdCall iocshEnvClear(const char *name)
Definition: iocsh.cpp:1054
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsEnvSet(const char *name, const char *value)
Set an environment variable&#39;s value.
Definition: osdEnv.c:35