-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathepicsEnvUnset.c
82 lines (74 loc) · 2.06 KB
/
epicsEnvUnset.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* epicsEnvUnset.c
*
* unset (delete) an environment variable
*
* Copyright (C) 2018 Dirk Zimoch
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "epicsVersion.h"
#ifdef BASE_VERSION
#define EPICS_3_13
#else
#include "iocsh.h"
#include "epicsStdioRedirect.h"
#include "epicsExport.h"
#endif
#include "epicsEnvUnset.h"
#ifdef vxWorks
/* Do the next best thing: invalidate the variable name */
#include <envLib.h>
#include <string.h>
void epicsEnvUnset (const char *name)
{
char* var;
if (!name) return;
var = getenv(name);
if (!var) return;
var -= strlen(name);
var --;
*var = 0;
}
#else
#include <stdlib.h>
void epicsEnvUnset (const char *name)
{
if (!name) return;
#ifdef _WIN32
/* simulate unset by setting a empty value */
char *cp = malloc(strlen(name) + 2);
strcpy(cp, name);
strcat(cp, "=");
if (putenv(cp) < 0)
fprintf(stderr, "Failed to unset environment parameter \"%s\"", name);
free(cp);
#else
unsetenv(name);
#endif
}
#endif
#ifndef EPICS_3_13
static const iocshArg epicsEnvUnsetArg0 = { "name", iocshArgString};
static const iocshArg * const epicsEnvUnsetArgs[1] = { &epicsEnvUnsetArg0 };
static const iocshFuncDef epicsEnvUnsetDef = { "epicsEnvUnset", 1, epicsEnvUnsetArgs };
static void epicsEnvUnsetFunc(const iocshArgBuf *args)
{
epicsEnvUnset(args[0].sval);
}
static void epicsEnvUnsetRegister(void)
{
iocshRegister (&epicsEnvUnsetDef, epicsEnvUnsetFunc);
}
epicsExportRegistrar(epicsEnvUnsetRegister);
#endif