chiark / gitweb /
[PATCH] klibc: strlcpy/strlcat - don't alter destination if size == 0
[elogind.git] / klibc / klibc / putenv.c
1 /*
2  * putenv.c
3  */
4
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9
10 /* str should be a duplicated version of the input string;
11    len is the length of the key including the = sign */
12 int __put_env(char *str, size_t len, int overwrite);
13
14 int putenv(const char *str)
15 {
16   char *s;
17   const char *e, *z;
18
19   if ( !str ) {
20     errno = EINVAL;
21     return -1;
22   }
23
24   e = NULL;
25   for ( z = str ; *z ; z++ ) {
26     if ( *z == '=' )
27       e = z;
28   }
29
30   if ( !e ) {
31     errno = EINVAL;
32     return -1;
33   }
34
35   s = strdup(str);
36   if ( !s )
37     return -1;
38
39   return __put_env(s, e-str, 1);
40 }