chiark / gitweb /
[PATCH] fix bug in klibc's isspace function.
[elogind.git] / klibc / klibc / unsetenv.c
1 /*
2  * unsetenv.c
3  */
4
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9
10 int unsetenv(const char *name)
11 {
12   size_t len;
13   char **p, *q;
14   const char *z;
15
16   if ( !name || !name[0] ) {
17     errno = EINVAL;
18     return -1;
19   }
20
21   len = 0;
22   for ( z = name ; *z ; z++ ) {
23     len++;
24     if ( *z == '=' ) {
25       errno = EINVAL;
26       return -1;
27     }
28   }
29
30   for ( p = environ ; (q = *p) ; p++ ) {
31     if ( !strncmp(name,q,len) && q[len] == '=' )
32       break;
33   }
34
35   for ( ; (q = *p) ; p++ ) {
36     p[0] = p[1];
37   }
38
39   return 0;
40 }