From 81ce150a961ef0509f63a1c2d09468712956c9ae Mon Sep 17 00:00:00 2001 From: eck Date: Thu, 27 Sep 1990 13:40:08 +0000 Subject: [PATCH] changed environment handling to decrease namespace pollution --- lang/cem/libcc.ansi/misc/.distr | 1 + lang/cem/libcc.ansi/misc/Makefile | 5 +++-- lang/cem/libcc.ansi/misc/environ.c | 20 ++++++++++++++++++++ lang/cem/libcc.ansi/misc/putenv.c | 20 +++++++++++--------- 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 lang/cem/libcc.ansi/misc/environ.c diff --git a/lang/cem/libcc.ansi/misc/.distr b/lang/cem/libcc.ansi/misc/.distr index f6201efa5..adb670e90 100644 --- a/lang/cem/libcc.ansi/misc/.distr +++ b/lang/cem/libcc.ansi/misc/.distr @@ -11,6 +11,7 @@ getw.c opendir.c popen.c putenv.c +environ.c putw.c readdir.c rewinddir.c diff --git a/lang/cem/libcc.ansi/misc/Makefile b/lang/cem/libcc.ansi/misc/Makefile index 40ccfad31..3980c58b7 100644 --- a/lang/cem/libcc.ansi/misc/Makefile +++ b/lang/cem/libcc.ansi/misc/Makefile @@ -1,4 +1,5 @@ clean: 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 + environ.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/environ.c b/lang/cem/libcc.ansi/misc/environ.c new file mode 100644 index 000000000..7e7fe73b0 --- /dev/null +++ b/lang/cem/libcc.ansi/misc/environ.c @@ -0,0 +1,20 @@ +/* + * environ.c - define the variable environ + */ +/* $Header$ */ +/* + * This file defines the variable environ and initializes it with a magic + * value. The C run-time start-off routine tests whether the variable + * environ is initialized with this value. If it is not, it is assumed + * that it is defined by the user. Only two bytes are tested, since we + * don't know the endian-ness and alignment restrictions of the machine. + * This means that the low-order two-bytes should be equal to the + * high-order two-bytes on machines with four-byte pointers. In fact, all + * the bytes in the pointer are the same, just in case. + */ + +#if _EM_PSIZE==2 +char **environ = (char **) 0x5353; +#else +char **environ = (char **) 0x53535353; +#endif diff --git a/lang/cem/libcc.ansi/misc/putenv.c b/lang/cem/libcc.ansi/misc/putenv.c index 206ebaa94..b7406c520 100644 --- a/lang/cem/libcc.ansi/misc/putenv.c +++ b/lang/cem/libcc.ansi/misc/putenv.c @@ -10,17 +10,18 @@ #define ENTRY_INC 10 #define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC) -extern const char **environ; +extern const char **_envp; +extern const char **environ; /* environ is a shadow name for _envp */ int putenv(char *name) { - register const char **v = environ; + register const char **v = _envp; 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]. + * last non-null entry is _envp[size - 2]. */ if (!name) return 0; @@ -47,7 +48,7 @@ putenv(char *name) } } *r = '='; - v = environ; + v = _envp; } if (!size) { @@ -61,17 +62,18 @@ putenv(char *name) if (!(v = malloc(rounded(i) * sizeof(char **)))) return 1; size = i; - p = environ; - environ = v; + p = _envp; + _envp = v; while (*v++ = *p++); /* copy the environment */ - v = environ; + v = _envp; } else if (!(size % ENTRY_INC)) { - if (!(v = realloc(environ, rounded(size) * sizeof(char **)))) + if (!(v = realloc(_envp, rounded(size) * sizeof(char **)))) return 1; - environ = v; + _envp = v; } v[size - 1] = name; v[size] = NULL; size++; + environ = _envp; return 0; } -- 2.34.1