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

Go to the source code of this file.

Macros

#define _VSB_CONFIG_FILE   <../lib/h/config/vsbConfig.h>
 

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...
 

Macro Definition Documentation

#define _VSB_CONFIG_FILE   <../lib/h/config/vsbConfig.h>

Definition at line 16 of file osdEnv.c.

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 35 of file osdEnv.c.

36 {
37  char *cp;
38 
39  if (!name) {
40  printf ("Usage: epicsEnvSet \"name\", \"value\"\n");
41  return;
42  }
43 
44  iocshEnvClear(name);
45 
46  cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
47  strcpy (cp, name);
48  strcat (cp, "=");
49  strcat (cp, value);
50  if (putenv (cp) < 0) {
51  errPrintf(-1L, __FILE__, __LINE__,
52  "Failed to set environment parameter \"%s\" to \"%s\": %s\n",
53  name, value, strerror (errno));
54  free (cp);
55  }
56 }
Definition: link.h:174
void epicsStdCall iocshEnvClear(const char *name)
Definition: iocsh.cpp:1054
#define printf
Definition: epicsStdio.h:41
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 80 of file osdEnv.c.

81 {
82  if (name == NULL) {
83  envShow (0);
84  }
85  else {
86  const char *cp = getenv (name);
87  if (cp == NULL)
88  printf ("%s is not an environment variable.\n", name);
89  else
90  printf ("%s=%s\n", name, cp);
91  }
92 }
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsEnvUnset ( const char *  name)

Clear the value of an environment variable.

Parameters
nameEnvironment variable name.

Definition at line 64 of file osdEnv.c.

65 {
66  char* var;
67 
68  if (!name) return;
69  iocshEnvClear(name);
70  var = getenv(name);
71  if (!var) return;
72  var -= strlen(name);
73  var --;
74  *var = 0;
75 }
void epicsStdCall iocshEnvClear(const char *name)
Definition: iocsh.cpp:1054