diff options
author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
---|---|---|
committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libwrap/setenv.c | |
download | illumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz |
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libwrap/setenv.c')
-rw-r--r-- | usr/src/lib/libwrap/setenv.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/usr/src/lib/libwrap/setenv.c b/usr/src/lib/libwrap/setenv.c new file mode 100644 index 0000000000..d4a53d2845 --- /dev/null +++ b/usr/src/lib/libwrap/setenv.c @@ -0,0 +1,44 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + /* + * Some systems do not have setenv(). This one is modeled after 4.4 BSD, but + * is implemented in terms of portable primitives only: getenv(), putenv() + * and malloc(). It should therefore be safe to use on every UNIX system. + * + * If clobber == 0, do not overwrite an existing variable. + * + * Returns nonzero if memory allocation fails. + * + * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. + */ + +#ifndef lint +static char sccsid[] = "@(#) setenv.c 1.1 93/03/07 22:47:58"; +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +/* setenv - update or insert environment (name,value) pair */ + +int setenv(name, value, clobber) +char *name; +char *value; +int clobber; +{ + char *cp; + + if (clobber == 0 && getenv(name) != 0) + return (0); + if ((cp = malloc(strlen(name) + strlen(value) + 2)) == 0) + return (1); + sprintf(cp, "%s=%s", name, value); + return (putenv(cp)); +} |