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.
11 #pragma ident "%Z%%M% %I% %E% SMI"
14 SM_RCSID("@(#)$Id: config.c,v 1.31 2007/03/14 21:21:49 ca Exp $")
18 #include <sm/string.h>
22 ** PUTENV -- emulation of putenv() in terms of setenv()
24 ** Not needed on Posix-compliant systems.
25 ** This doesn't have full Posix semantics, but it's good enough
29 ** env -- the environment to put.
32 ** 0 on success, < 0 on failure.
37 # if NEEDPUTENV == 2 /* no setenv(3) call available */
44 int matchlen
, envlen
= 0;
47 static bool first
= true;
48 extern char **environ
;
51 ** find out how much of str to match when searching
52 ** for a string to replace.
55 if ((tmp
= strchr(str
, '=')) == NULL
|| tmp
== str
)
56 matchlen
= strlen(str
);
58 matchlen
= (int) (tmp
- str
);
62 ** Search for an existing string in the environment and find the
63 ** length of environ. If found, replace and exit.
66 for (current
= environ
; *current
!= NULL
; current
++)
70 if (strncmp(str
, *current
, matchlen
) == 0)
72 /* found it, now insert the new version */
73 *current
= (char *) str
;
79 ** There wasn't already a slot so add space for a new slot.
80 ** If this is our first time through, use malloc(), else realloc().
85 newenv
= (char **) sm_malloc(sizeof(char *) * (envlen
+ 2));
90 (void) memcpy(newenv
, environ
, sizeof(char *) * envlen
);
94 newenv
= (char **) sm_realloc((char *) environ
,
95 sizeof(char *) * (envlen
+ 2));
100 /* actually add in the new entry */
102 environ
[envlen
] = (char *) str
;
103 environ
[envlen
+ 1] = NULL
;
108 # else /* NEEDPUTENV == 2 */
118 p
= strchr(env
, '=');
122 if (l
> sizeof nbuf
- 1)
124 memmove(nbuf
, env
, l
);
126 return setenv(nbuf
, ++p
, 1);
129 # endif /* NEEDPUTENV == 2 */
130 #endif /* NEEDPUTENV */
132 ** UNSETENV -- remove a variable from the environment
134 ** Not needed on newer systems.
137 ** name -- the string name of the environment variable to be
138 ** deleted from the current environment.
144 ** environ -- a pointer to the current environment.
156 extern char **environ
;
158 int len
= strlen(name
);
160 for (pp
= environ
; *pp
!= NULL
; pp
++)
162 if (strncmp(name
, *pp
, len
) == 0 &&
163 ((*pp
)[len
] == '=' || (*pp
)[len
] == '\0'))
167 for (; *pp
!= NULL
; pp
++)
171 #endif /* !HASUNSETENV */
173 char *SmCompileOptions
[] =
175 #if SM_CONF_BROKEN_STRTOD
176 "SM_CONF_BROKEN_STRTOD",
177 #endif /* SM_CONF_BROKEN_STRTOD */
180 #endif /* SM_CONF_GETOPT */
181 #if SM_CONF_LDAP_INITIALIZE
182 "SM_CONF_LDAP_INITIALIZE",
183 #endif /* SM_CONF_LDAP_INITIALIZE */
184 #if SM_CONF_LDAP_MEMFREE
185 "SM_CONF_LDAP_MEMFREE",
186 #endif /* SM_CONF_LDAP_MEMFREE */
189 #endif /* SM_CONF_LONGLONG */
192 #endif /* SM_CONF_MEMCHR */
195 #endif /* SM_CONF_MSG */
198 #endif /* SM_CONF_QUAD_T */
201 #endif /* SM_CONF_SEM */
202 #if SM_CONF_SETITIMER
204 #endif /* SM_CONF_SETITIMER */
205 #if SM_CONF_SIGSETJMP
207 #endif /* SM_CONF_SIGSETJMP */
210 #endif /* SM_CONF_SHM */
211 #if SM_CONF_SHM_DELAY
213 #endif /* SM_CONF_SHM_DELAY */
216 #endif /* SM_CONF_SSIZE_T */
217 #if SM_CONF_STDBOOL_H
219 #endif /* SM_CONF_STDBOOL_H */
222 #endif /* SM_CONF_STDDEF_H */
225 /* XXX this is always enabled (for now) */
228 #endif /* SM_CONF_STRL */
231 #if SM_CONF_SYS_CDEFS_H
232 "SM_CONF_SYS_CDEFS_H",
233 #endif /* SM_CONF_SYS_CDEFS_H */
234 #if SM_CONF_SYSEXITS_H
235 "SM_CONF_SYSEXITS_H",
236 #endif /* SM_CONF_SYSEXITS_H */
239 #endif /* SM_CONF_UID_GID */
240 #if DO_NOT_USE_STRCPY
242 #endif /* DO_NOT_USE_STRCPY */
245 #endif /* SM_HEAP_CHECK */
246 #if defined(SM_OS_NAME) && defined(__STDC__)
247 "SM_OS=sm_os_" SM_OS_NAME
,
248 #endif /* defined(SM_OS_NAME) && defined(__STDC__) */
251 #endif /* SM_VA_STD */
254 #endif /* USEKSTAT */
257 #endif /* USEPROCMEMINFO */
260 #endif /* USESWAPCTL */