Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/setenv.c

Parent Directory Parent Directory | Revision Log 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: 571 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 * setenv.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 setenv(const char *name, const char *val, int overwrite)
12 {
13 const char *z;
14 char *s;
15 size_t l1, l2;
16
17 if (!name || !name[0]) {
18 errno = EINVAL;
19 return -1;
20 }
21
22 l1 = 0;
23 for (z = name; *z; z++) {
24 l1++;
25 if (*z == '=') {
26 errno = EINVAL;
27 return -1;
28 }
29 }
30
31 l2 = strlen(val);
32
33 s = malloc(l1 + l2 + 2);
34 if (!s)
35 return -1;
36
37 memcpy(s, name, l1);
38 s[l1] = '=';
39 memcpy(s + l1 + 1, val, l2 + 1);
40
41 return __put_env(s, l1 + 1, overwrite);
42 }