changed environment handling to decrease namespace pollution
authoreck <none@none>
Thu, 27 Sep 1990 13:40:08 +0000 (13:40 +0000)
committereck <none@none>
Thu, 27 Sep 1990 13:40:08 +0000 (13:40 +0000)
lang/cem/libcc.ansi/misc/.distr
lang/cem/libcc.ansi/misc/Makefile
lang/cem/libcc.ansi/misc/environ.c [new file with mode: 0644]
lang/cem/libcc.ansi/misc/putenv.c

index f6201ef..adb670e 100644 (file)
@@ -11,6 +11,7 @@ getw.c
 opendir.c
 popen.c
 putenv.c
+environ.c
 putw.c
 readdir.c
 rewinddir.c
index 40ccfad..3980c58 100644 (file)
@@ -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 (file)
index 0000000..7e7fe73
--- /dev/null
@@ -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
index 206ebaa..b7406c5 100644 (file)
 #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;
 }