mlib update: new isnan()/isnanf() implementation
[tangerine.git] / compiler / clib / putenv.c
blob1b98421bd68ca610f12499d2f740514245cb22bd
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function putenv().
6 */
8 #include <proto/dos.h>
9 #include <dos/var.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <errno.h>
16 /*****************************************************************************
18 NAME */
19 #include <stdlib.h>
21 int putenv (
23 /* SYNOPSIS */
24 const char *string)
26 /* FUNCTION
27 Change or add an environment variable.
29 INPUTS
30 string - Is of the form "name=value", where name is the variable's
31 name and value is its value. In case the string is of the form
32 "name" then the variable is removed from the environment.
33 RESULT
34 The putenv() function returns zero on success, or -1 if an
35 error occurs. In such a case the errno variable is set
36 appropriately.
38 NOTES
39 This function must not be used in a shared library.
40 Conforming to BSD4.4 in that it makes a copy of the argument string.
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 ******************************************************************************/
52 char *name = NULL, *value = NULL, *ptr;
53 int res = -1;
55 if (!string)
57 errno = EFAULT;
58 goto err;
61 name = strdup(string);
62 if (!name) return -1;
64 for (ptr=name; *ptr!='\0' && *ptr!='='; ptr++)
66 if (isspace(*ptr))
68 errno = EINVAL;
69 goto err;
73 /* No value means we have to delete the variable */
74 if (*ptr == '\0')
75 res = 0, unsetenv(name);
77 /* we might have a value to get */
78 else
80 *ptr = '\0'; /*terminate the name string */
81 for (value=++ptr; *ptr!='\0'; ptr++)
83 if (isspace(*ptr))
85 errno = EINVAL;
86 goto err;
90 res = setenv(name, value, 1);
93 err:
94 if (name)
95 free(name);
97 return res;
98 } /* putenv */