From 670ca5a83a87e67f68cf67f294c4919cd54ff0f6 Mon Sep 17 00:00:00 2001 From: eck Date: Wed, 3 Jan 1990 17:23:10 +0000 Subject: [PATCH] added putenv.c --- lang/cem/libcc.ansi/misc/.distr | 1 + lang/cem/libcc.ansi/misc/LIST | 1 + lang/cem/libcc.ansi/misc/Makefile | 2 +- lang/cem/libcc.ansi/misc/putenv.c | 76 +++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 lang/cem/libcc.ansi/misc/putenv.c diff --git a/lang/cem/libcc.ansi/misc/.distr b/lang/cem/libcc.ansi/misc/.distr index afac1241f..f6201efa5 100644 --- a/lang/cem/libcc.ansi/misc/.distr +++ b/lang/cem/libcc.ansi/misc/.distr @@ -10,6 +10,7 @@ getpw.c getw.c opendir.c popen.c +putenv.c putw.c readdir.c rewinddir.c diff --git a/lang/cem/libcc.ansi/misc/LIST b/lang/cem/libcc.ansi/misc/LIST index ab676f088..bd8564c46 100644 --- a/lang/cem/libcc.ansi/misc/LIST +++ b/lang/cem/libcc.ansi/misc/LIST @@ -4,6 +4,7 @@ getpass.c getpw.c getw.c putw.c +putenv.c popen.c sleep.c termcap.c diff --git a/lang/cem/libcc.ansi/misc/Makefile b/lang/cem/libcc.ansi/misc/Makefile index 8fb4d551b..40ccfad31 100644 --- a/lang/cem/libcc.ansi/misc/Makefile +++ b/lang/cem/libcc.ansi/misc/Makefile @@ -1,4 +1,4 @@ clean: - rm -f getgrent.o getopt.o getpass.o getpw.o getw.o putw.o \ + rm -f getgrent.o getopt.o getpass.o getpw.o getw.o putw.o putenv.o \ popen.o sleep.o termcap.o fdopen.o closedir.o getdents.o \ opendir.o readdir.o rewinddir.o seekdir.o telldir.o OLIST diff --git a/lang/cem/libcc.ansi/misc/putenv.c b/lang/cem/libcc.ansi/misc/putenv.c new file mode 100644 index 000000000..5caedf64b --- /dev/null +++ b/lang/cem/libcc.ansi/misc/putenv.c @@ -0,0 +1,76 @@ +/* + * (c) copyright 1989 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Header$ */ + +#include +#include + +#define ENTRY_INC 10 +#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC) + +extern const char **environ; + +int +putenv(char *name) +{ + register const char **v = environ; + register char *r; + static int size = 0; + /* When size != 0, it contains the number of entries in the + * table (including the final NULL pointer). This means that the + * last non-null entry is environ[size - 2]. + */ + + if (!name) return 0; + if (r = strrchr(name, '=')) { + register const char *p, *q; + + *r = '\0'; + + if (v != NULL) { + while ((p = *v) != NULL) { + q = name; + while (*q && (*q++ == *p++)) + /* EMPTY */ ; + if (*q || (*p != '=')) { + v++; + } else { + /* The name was already in the + * environment. + */ + *r = '='; + *v = name; + return 0; + } + } + } + v = environ; + } + + if (!size) { + register const char **p; + register int i = 0; + + if (v) + do { + i++; + } while (*v++); + if (!(v = malloc(rounded(i) * sizeof(char **)))) + return 1; + size = i; + p = environ; + environ = v; + while (*v++ = *p++); /* copy the environment */ + v = environ; + } else if (!(size % ENTRY_INC)) { + if (!(v = realloc(environ, rounded(size) * sizeof(char **)))) + return 1; + environ = v; + } + v[size - 1] = name; + v[size] = NULL; + size++; + return 0; +} -- 2.34.1