Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/unsetenv.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 546 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 546 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
2 | * unsetenv.c |
3 | */ |
4 | |
5 | #include <errno.h> |
6 | #include <stdlib.h> |
7 | #include <string.h> |
8 | #include <unistd.h> |
9 | #include "env.h" |
10 | |
11 | int unsetenv(const char *name) |
12 | { |
13 | size_t len; |
14 | char **p, *q; |
15 | const char *z; |
16 | |
17 | if (!name || !name[0]) { |
18 | errno = EINVAL; |
19 | return -1; |
20 | } |
21 | |
22 | len = 0; |
23 | for (z = name; *z; z++) { |
24 | len++; |
25 | if (*z == '=') { |
26 | errno = EINVAL; |
27 | return -1; |
28 | } |
29 | } |
30 | |
31 | if (!environ) |
32 | return 0; |
33 | |
34 | for (p = environ; (q = *p); p++) { |
35 | if (!strncmp(name, q, len) && q[len] == '=') |
36 | break; |
37 | } |
38 | |
39 | for (; (q = *p); p++) { |
40 | p[0] = p[1]; |
41 | } |
42 | |
43 | return 0; |
44 | } |