File: setenv.c

package info (click to toggle)
nut 0.45.5-rel-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,984 kB
  • ctags: 2,146
  • sloc: ansic: 22,216; sh: 1,138; makefile: 405
file content (26 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* setenv.c Ben Collver <collver@softhome.net> */
#ifndef HAVE_SETENV
#include <stdlib.h>
#include <string.h>
#include "common.h"

int setenv(const char *name, const char *value, int overwrite)
{
	char	*val;
	char	*buffer;
	int	rv;
 
	if (overwrite == 0) {
		val = getenv(name);
		if (val != NULL) {
			return 0;
		}
	}
	buffer = xmalloc(strlen(value) + strlen(name) + 2);
	strcpy(buffer, name);
	strcat(buffer, "=");
	strcat(buffer, value);
	rv = putenv(buffer); /* man putenv, do not free(buffer) */
	return (rv);
}
#endif