]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/RCS/putenv.c,v
Exposed a bunch of switches that are now documented.
[nmh] / docs / historical / mh-6.8.5 / sbr / RCS / putenv.c,v
1 head 1.6;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.6
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.5;
12
13 1.5
14 date 92.11.04.00.37.05; author jromine; state Exp;
15 branches;
16 next 1.4;
17
18 1.4
19 date 90.04.05.15.32.08; author sources; state Exp;
20 branches;
21 next 1.3;
22
23 1.3
24 date 90.04.05.14.49.34; author sources; state Exp;
25 branches;
26 next 1.2;
27
28 1.2
29 date 90.02.06.13.08.41; author sources; state Exp;
30 branches;
31 next 1.1;
32
33 1.1
34 date 90.02.06.13.06.05; author sources; state Exp;
35 branches;
36 next ;
37
38
39 desc
40 @
41 @
42
43
44 1.6
45 log
46 @endif sugar
47 @
48 text
49 @/* putenv.c - (un) set an envariable */
50 #ifndef lint
51 static char ident[] = "@@(#)$Id: putenv.c,v 1.5 1992/11/04 00:37:05 jromine Exp jromine $";
52 #endif /* lint */
53
54 #include "../h/mh.h"
55 #include <stdio.h>
56
57
58 extern char **environ;
59
60 static nvmatch();
61
62 int m_putenv (name, value)
63 register char *name,
64 *value;
65 {
66 register int i;
67 register char **ep,
68 **nep,
69 *cp;
70
71 if ((cp = malloc ((unsigned) (strlen (name) + strlen (value) + 2)))
72 == NULL)
73 return 1;
74 (void) sprintf (cp, "%s=%s", name, value);
75
76 for (ep = environ, i = 0; *ep; ep++, i++)
77 if (nvmatch (name, *ep)) {
78 *ep = cp;
79 return 0;
80 }
81
82 if ((nep = (char **) malloc ((unsigned) ((i + 2) * sizeof *nep))) == NULL)
83 return 1;
84 for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
85 continue;
86 nep[i++] = cp;
87 nep[i] = NULL;
88 environ = nep;
89 return 0;
90 }
91
92
93 int unputenv (name)
94 char *name;
95 {
96 char **ep,
97 **nep;
98
99 for (ep = environ; *ep; ep++)
100 if (nvmatch (name, *ep))
101 break;
102 if (*ep == NULL)
103 return 1;
104
105 for (nep = ep + 1; *nep; nep++)
106 continue;
107 *ep = *--nep;
108 *nep = NULL;
109 return 0;
110 }
111
112 /* \f */
113
114 static nvmatch (s1, s2)
115 register char *s1,
116 *s2;
117 {
118 while (*s1 == *s2++)
119 if (*s1++ == '=')
120 return 1;
121
122 return (*s1 == '\0' && *--s2 == '=');
123 }
124 @
125
126
127 1.5
128 log
129 @putenv -> m_putenv
130 @
131 text
132 @d3 2
133 a4 2
134 static char ident[] = "@@(#)$Id: putenv.c,v 1.4 1990/04/05 15:32:08 sources Exp jromine $";
135 #endif lint
136 @
137
138
139 1.4
140 log
141 @add ID
142 @
143 text
144 @d3 1
145 a3 1
146 static char ident[] = "@@(#)$Id:$";
147 d14 1
148 a14 1
149 int putenv (name, value)
150 @
151
152
153 1.3
154 log
155 @add ID
156 @
157 text
158 @d3 1
159 a3 1
160 static char ident[] = "$Id:";
161 @
162
163
164 1.2
165 log
166 @ANSI Compilance
167 @
168 text
169 @d2 3
170 @
171
172
173 1.1
174 log
175 @Initial revision
176 @
177 text
178 @d9 1
179 @