add a missing section header table index conversion
[tangerine.git] / compiler / clib / putenv.c
blob74a28030c70edc20aee13f90afc06a5af62fb8e7
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 value = ++ptr;
82 res = setenv(name, value, 1);
85 err:
86 if (name)
87 free(name);
89 return res;
90 } /* putenv */