Merge Dirk Zimoch's 'epicsEnvUnset' branch into 3.15
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
|
||||
<!-- Insert new items immediately below here ... -->
|
||||
|
||||
<h3>Unsetting environment variables</h3>
|
||||
|
||||
<p>The new command <code>epicsEnvUnset <i>varname</i></code> can be used to
|
||||
unset an environment variable.</p>
|
||||
|
||||
<h3>Warning indicators in msi (and macLib) output</h3>
|
||||
|
||||
<p>The libCom macro expansion library has been modified so that when the
|
||||
|
||||
1
src/libCom/env/envDefs.h
vendored
1
src/libCom/env/envDefs.h
vendored
@@ -95,6 +95,7 @@ epicsShareFunc long epicsShareAPI
|
||||
envGetBoolConfigParam(const ENV_PARAM *pParam, int *pBool);
|
||||
epicsShareFunc long epicsShareAPI epicsPrtEnvParams(void);
|
||||
epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *value);
|
||||
epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name);
|
||||
epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -110,6 +110,21 @@ static void epicsEnvSetCallFunc(const iocshArgBuf *args)
|
||||
epicsEnvSet (name, value);
|
||||
}
|
||||
|
||||
/* epicsEnvUnset */
|
||||
static const iocshArg epicsEnvUnsetArg0 = { "name",iocshArgString};
|
||||
static const iocshArg * const epicsEnvUnsetArgs[1] = {&epicsEnvUnsetArg0};
|
||||
static const iocshFuncDef epicsEnvUnsetFuncDef = {"epicsEnvUnset",1,epicsEnvUnsetArgs};
|
||||
static void epicsEnvUnsetCallFunc(const iocshArgBuf *args)
|
||||
{
|
||||
char *name = args[0].sval;
|
||||
|
||||
if (name == NULL) {
|
||||
fprintf(stderr, "Missing environment variable name argument.\n");
|
||||
return;
|
||||
}
|
||||
epicsEnvUnset (name);
|
||||
}
|
||||
|
||||
/* epicsParamShow */
|
||||
static const iocshFuncDef epicsParamShowFuncDef = {"epicsParamShow",0,NULL};
|
||||
static void epicsParamShowCallFunc(const iocshArgBuf *args)
|
||||
@@ -367,6 +382,7 @@ void epicsShareAPI libComRegister(void)
|
||||
iocshRegister(&pwdFuncDef, pwdCallFunc);
|
||||
|
||||
iocshRegister(&epicsEnvSetFuncDef, epicsEnvSetCallFunc);
|
||||
iocshRegister(&epicsEnvUnsetFuncDef, epicsEnvUnsetCallFunc);
|
||||
iocshRegister(&epicsParamShowFuncDef, epicsParamShowCallFunc);
|
||||
iocshRegister(&epicsPrtEnvParamsFuncDef, epicsPrtEnvParamsCallFunc);
|
||||
iocshRegister(&epicsEnvShowFuncDef, epicsEnvShowCallFunc);
|
||||
|
||||
@@ -39,6 +39,16 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
|
||||
@@ -55,6 +55,18 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
* Using putenv with a an existing name but without "=..." deletes
|
||||
*/
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
if (getenv(name) != NULL)
|
||||
putenv((char*)name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,16 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,25 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
* Basically destroy the name of that variable because vxWorks does not
|
||||
* support to really unset an environment variable.
|
||||
*/
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
|
||||
{
|
||||
char* var;
|
||||
|
||||
if (!name) return;
|
||||
iocshEnvClear(name);
|
||||
var = getenv(name);
|
||||
if (!var) return;
|
||||
var -= strlen(name);
|
||||
var --;
|
||||
*var = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
|
||||
@@ -62,6 +62,11 @@ epicsEnvTest_SRCS += epicsEnvTest.c
|
||||
testHarness_SRCS += epicsEnvTest.c
|
||||
TESTS += epicsEnvTest
|
||||
|
||||
TESTPROD_HOST += epicsEnvUnsetTest
|
||||
epicsEnvUnsetTest_SRCS += epicsEnvUnsetTest.c
|
||||
testHarness_SRCS += epicsEnvUnsetTest.c
|
||||
TESTS += epicsEnvUnsetTest
|
||||
|
||||
TESTPROD_HOST += epicsErrlogTest
|
||||
epicsErrlogTest_SRCS += epicsErrlogTest.c
|
||||
testHarness_SRCS += epicsErrlogTest.c
|
||||
|
||||
37
src/libCom/test/epicsEnvUnsetTest.c
Normal file
37
src/libCom/test/epicsEnvUnsetTest.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macLib.h"
|
||||
#include "envDefs.h"
|
||||
#include "errlog.h"
|
||||
#include "epicsUnitTest.h"
|
||||
#include "testMain.h"
|
||||
|
||||
static void check(const char* variable, const char* expected)
|
||||
{
|
||||
const char* value;
|
||||
|
||||
value = getenv(variable);
|
||||
if (!testOk((!expected && !value) || (expected && value && strcmp(expected, value) == 0),
|
||||
"%s = \"%s\"", variable, value))
|
||||
{
|
||||
testDiag("should have been \"%s\"", expected);
|
||||
}
|
||||
}
|
||||
|
||||
MAIN(epicsEnvUnsetTest)
|
||||
{
|
||||
eltc(0);
|
||||
testPlan(3);
|
||||
|
||||
check("TEST_VAR_A",NULL);
|
||||
epicsEnvSet("TEST_VAR_A","test value");
|
||||
check("TEST_VAR_A","test value");
|
||||
epicsEnvUnset("TEST_VAR_A");
|
||||
check("TEST_VAR_A",NULL);
|
||||
|
||||
testDone();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user