opendir.c
popen.c
putenv.c
+environ.c
putw.c
readdir.c
rewinddir.c
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
--- /dev/null
+/*
+ * 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
#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;
}
}
*r = '=';
- v = environ;
+ v = _envp;
}
if (!size) {
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;
}