PCI: adds device-specific data pointer
[akaros.git] / user / bsd / putenv.c
1 /* 
2  * This file is part of the UCB release of Plan 9. It is subject to the license
3  * terms in the LICENSE file found in the top-level directory of this
4  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
5  * part of the UCB release of Plan 9, including this file, may be copied,
6  * modified, propagated, or distributed except according to the terms contained
7  * in the LICENSE file.
8  */
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <string.h>
13
14 #include "priv.h"
15
16 int
17 putenv(char *s)
18 {
19         int f, n;
20         char *value;
21         char buf[300];
22
23         value = strchr(s, '=');
24         if (value) {
25                 n = value-s;
26                 if(n<=0 || n > sizeof(buf)-6)
27                         return -1;
28                 strcpy(buf, "/env/");
29                 strncpy(buf+5, s, n);
30                 buf[n+5] = 0;
31                 f = creat(buf, 0666);
32                 if(f < 0)
33                         return 1;
34                 value++;
35                 n = strlen(value);
36                 if(write(f, value, n) != n)
37                         return -1;
38                 close(f);
39                 return 0;
40         } else
41                 return -1;
42 }