2 * Copyright (c) 2000-2003, 2007 Sendmail, Inc. and its suppliers.
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.
12 SM_RCSID("@(#)$Id: config.c,v 1.31 2007/03/14 21:21:49 ca Exp $")
16 #include <sm/string.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
27 ** env -- the environment to put.
30 ** 0 on success, < 0 on failure.
35 # if NEEDPUTENV == 2 /* no setenv(3) call available */
42 int matchlen
, envlen
= 0;
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
);
56 matchlen
= (int) (tmp
- str
);
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
++)
68 if (strncmp(str
, *current
, matchlen
) == 0)
70 /* found it, now insert the new version */
71 *current
= (char *) str
;
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().
83 newenv
= (char **) sm_malloc(sizeof(char *) * (envlen
+ 2));
88 (void) memcpy(newenv
, environ
, sizeof(char *) * envlen
);
92 newenv
= (char **) sm_realloc((char *) environ
,
93 sizeof(char *) * (envlen
+ 2));
98 /* actually add in the new entry */
100 environ
[envlen
] = (char *) str
;
101 environ
[envlen
+ 1] = NULL
;
106 # else /* NEEDPUTENV == 2 */
116 p
= strchr(env
, '=');
120 if (l
> sizeof nbuf
- 1)
122 memmove(nbuf
, env
, l
);
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.
135 ** name -- the string name of the environment variable to be
136 ** deleted from the current environment.
142 ** environ -- a pointer to the current environment.
154 extern char **environ
;
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'))
165 for (; *pp
!= NULL
; pp
++)
169 #endif /* !HASUNSETENV */
171 char *SmCompileOptions
[] =
173 #if SM_CONF_BROKEN_STRTOD
174 "SM_CONF_BROKEN_STRTOD",
175 #endif /* SM_CONF_BROKEN_STRTOD */
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 */
187 #endif /* SM_CONF_LONGLONG */
190 #endif /* SM_CONF_MEMCHR */
193 #endif /* SM_CONF_MSG */
196 #endif /* SM_CONF_QUAD_T */
199 #endif /* SM_CONF_SEM */
200 #if SM_CONF_SETITIMER
202 #endif /* SM_CONF_SETITIMER */
203 #if SM_CONF_SIGSETJMP
205 #endif /* SM_CONF_SIGSETJMP */
208 #endif /* SM_CONF_SHM */
209 #if SM_CONF_SHM_DELAY
211 #endif /* SM_CONF_SHM_DELAY */
214 #endif /* SM_CONF_SSIZE_T */
215 #if SM_CONF_STDBOOL_H
217 #endif /* SM_CONF_STDBOOL_H */
220 #endif /* SM_CONF_STDDEF_H */
223 /* XXX this is always enabled (for now) */
226 #endif /* SM_CONF_STRL */
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 */
237 #endif /* SM_CONF_UID_GID */
238 #if DO_NOT_USE_STRCPY
240 #endif /* DO_NOT_USE_STRCPY */
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__) */
249 #endif /* SM_VA_STD */
252 #endif /* USEKSTAT */
255 #endif /* USEPROCMEMINFO */
258 #endif /* USESWAPCTL */