Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/ape/lib/bsd/putenv.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <sys/types.h>
2
#include <unistd.h>
3
#include <fcntl.h>
4
#include <string.h>
5
 
6
int
7
putenv(char *s)
8
{
9
	int f, n;
10
	char *value;
11
	char buf[300];
12
 
13
	value = strchr(s, '=');
14
	if (value) {
15
		n = value-s;
16
		if(n<=0 || n > sizeof(buf)-6)
17
			return -1;
18
		strcpy(buf, "/env/");
19
		strncpy(buf+5, s, n);
20
		buf[n+5] = 0;
21
		f = creat(buf, 0666);
22
		if(f < 0)
23
			return 1;
24
		value++;
25
		n = strlen(value);
26
		if(write(f, value, n) != n)
27
			return -1;
28
		close(f);
29
		return 0;
30
	} else
31
		return -1;
32
}