Import sendmail 8.13.4 into a new contrib directory as the first step
[dragonfly.git] / contrib / sendmail-8.13.4 / libsm / config.c
bloba5e13270a0968301a4ca242ea34bfa8916014f1d
1 /*
2 * Copyright (c) 2000-2003 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 */
11 #include <sm/gen.h>
12 SM_RCSID("@(#)$Id: config.c,v 1.30 2003/12/10 03:19:07 gshapiro Exp $")
14 #include <stdlib.h>
15 #include <sm/heap.h>
16 #include <sm/string.h>
17 #include <sm/conf.h>
20 ** PUTENV -- emulation of putenv() in terms of setenv()
22 ** Not needed on Posix-compliant systems.
23 ** This doesn't have full Posix semantics, but it's good enough
24 ** for sendmail.
26 ** Parameter:
27 ** env -- the environment to put.
29 ** Returns:
30 ** 0 on success, < 0 on failure.
33 #if NEEDPUTENV
35 # if NEEDPUTENV == 2 /* no setenv(3) call available */
37 int
38 putenv(str)
39 char *str;
41 char **current;
42 int matchlen, envlen = 0;
43 char *tmp;
44 char **newenv;
45 static bool first = true;
46 extern char **environ;
49 ** find out how much of str to match when searching
50 ** for a string to replace.
53 if ((tmp = strchr(str, '=')) == NULL || tmp == str)
54 matchlen = strlen(str);
55 else
56 matchlen = (int) (tmp - str);
57 ++matchlen;
60 ** Search for an existing string in the environment and find the
61 ** length of environ. If found, replace and exit.
64 for (current = environ; *current != NULL; current++)
66 ++envlen;
68 if (strncmp(str, *current, matchlen) == 0)
70 /* found it, now insert the new version */
71 *current = (char *) str;
72 return 0;
77 ** There wasn't already a slot so add space for a new slot.
78 ** If this is our first time through, use malloc(), else realloc().
81 if (first)
83 newenv = (char **) sm_malloc(sizeof(char *) * (envlen + 2));
84 if (newenv == NULL)
85 return -1;
87 first = false;
88 (void) memcpy(newenv, environ, sizeof(char *) * envlen);
90 else
92 newenv = (char **) sm_realloc((char *) environ,
93 sizeof(char *) * (envlen + 2));
94 if (newenv == NULL)
95 return -1;
98 /* actually add in the new entry */
99 environ = newenv;
100 environ[envlen] = (char *) str;
101 environ[envlen + 1] = NULL;
103 return 0;
106 # else /* NEEDPUTENV == 2 */
109 putenv(env)
110 char *env;
112 char *p;
113 int l;
114 char nbuf[100];
116 p = strchr(env, '=');
117 if (p == NULL)
118 return 0;
119 l = p - env;
120 if (l > sizeof nbuf - 1)
121 l = sizeof nbuf - 1;
122 memmove(nbuf, env, l);
123 nbuf[l] = '\0';
124 return setenv(nbuf, ++p, 1);
127 # endif /* NEEDPUTENV == 2 */
128 #endif /* NEEDPUTENV */
130 ** UNSETENV -- remove a variable from the environment
132 ** Not needed on newer systems.
134 ** Parameters:
135 ** name -- the string name of the environment variable to be
136 ** deleted from the current environment.
138 ** Returns:
139 ** none.
141 ** Globals:
142 ** environ -- a pointer to the current environment.
144 ** Side Effects:
145 ** Modifies environ.
148 #if !HASUNSETENV
150 void
151 unsetenv(name)
152 char *name;
154 extern char **environ;
155 register char **pp;
156 int len = strlen(name);
158 for (pp = environ; *pp != NULL; pp++)
160 if (strncmp(name, *pp, len) == 0 &&
161 ((*pp)[len] == '=' || (*pp)[len] == '\0'))
162 break;
165 for (; *pp != NULL; pp++)
166 *pp = pp[1];
169 #endif /* !HASUNSETENV */
171 char *SmCompileOptions[] =
173 #if SM_CONF_BROKEN_STRTOD
174 "SM_CONF_BROKEN_STRTOD",
175 #endif /* SM_CONF_BROKEN_STRTOD */
176 #if SM_CONF_GETOPT
177 "SM_CONF_GETOPT",
178 #endif /* SM_CONF_GETOPT */
179 #if SM_CONF_LDAP_INITIALIZE
180 "SM_CONF_LDAP_INITIALIZE",
181 #endif /* SM_CONF_LDAP_INITIALIZE */
182 #if SM_CONF_LDAP_MEMFREE
183 "SM_CONF_LDAP_MEMFREE",
184 #endif /* SM_CONF_LDAP_MEMFREE */
185 #if SM_CONF_LONGLONG
186 "SM_CONF_LONGLONG",
187 #endif /* SM_CONF_LONGLONG */
188 #if SM_CONF_MEMCHR
189 "SM_CONF_MEMCHR",
190 #endif /* SM_CONF_MEMCHR */
191 #if SM_CONF_MSG
192 "SM_CONF_MSG",
193 #endif /* SM_CONF_MSG */
194 #if SM_CONF_QUAD_T
195 "SM_CONF_QUAD_T",
196 #endif /* SM_CONF_QUAD_T */
197 #if SM_CONF_SEM
198 "SM_CONF_SEM",
199 #endif /* SM_CONF_SEM */
200 #if SM_CONF_SETITIMER
201 "SM_CONF_SETITIMER",
202 #endif /* SM_CONF_SETITIMER */
203 #if SM_CONF_SIGSETJMP
204 "SM_CONF_SIGSETJMP",
205 #endif /* SM_CONF_SIGSETJMP */
206 #if SM_CONF_SHM
207 "SM_CONF_SHM",
208 #endif /* SM_CONF_SHM */
209 #if SM_CONF_SHM_DELAY
210 "SM_CONF_SHM_DELAY",
211 #endif /* SM_CONF_SHM_DELAY */
212 #if SM_CONF_SSIZE_T
213 "SM_CONF_SSIZE_T",
214 #endif /* SM_CONF_SSIZE_T */
215 #if SM_CONF_STDBOOL_H
216 "SM_CONF_STDBOOL_H",
217 #endif /* SM_CONF_STDBOOL_H */
218 #if SM_CONF_STDDEF_H
219 "SM_CONF_STDDEF_H",
220 #endif /* SM_CONF_STDDEF_H */
222 #if 0
223 /* XXX this is always enabled (for now) */
224 #if SM_CONF_STRL
225 "SM_CONF_STRL",
226 #endif /* SM_CONF_STRL */
227 #endif /* 0 */
229 #if SM_CONF_SYS_CDEFS_H
230 "SM_CONF_SYS_CDEFS_H",
231 #endif /* SM_CONF_SYS_CDEFS_H */
232 #if SM_CONF_SYSEXITS_H
233 "SM_CONF_SYSEXITS_H",
234 #endif /* SM_CONF_SYSEXITS_H */
235 #if SM_CONF_UID_GID
236 "SM_CONF_UID_GID",
237 #endif /* SM_CONF_UID_GID */
238 #if DO_NOT_USE_STRCPY
239 "DO_NOT_USE_STRCPY",
240 #endif /* DO_NOT_USE_STRCPY */
241 #if SM_HEAP_CHECK
242 "SM_HEAP_CHECK",
243 #endif /* SM_HEAP_CHECK */
244 #if defined(SM_OS_NAME) && defined(__STDC__)
245 "SM_OS=sm_os_" SM_OS_NAME,
246 #endif /* defined(SM_OS_NAME) && defined(__STDC__) */
247 #if SM_VA_STD
248 "SM_VA_STD",
249 #endif /* SM_VA_STD */
250 NULL