oops, _envp should have been _penvp
This commit is contained in:
parent
e1a20fe944
commit
c937359a4e
4 changed files with 27 additions and 18 deletions
|
@ -53,7 +53,7 @@ _penvp
|
||||||
loc 21331 /* == 0x5353 */
|
loc 21331 /* == 0x5353 */
|
||||||
bne *1
|
bne *1
|
||||||
/* environ contains the magic value. Assume it's our own environ */
|
/* environ contains the magic value. Assume it's our own environ */
|
||||||
lae _envp
|
lae _penvp
|
||||||
loi _EM_PSIZE
|
loi _EM_PSIZE
|
||||||
lae environ
|
lae environ
|
||||||
sti _EM_PSIZE
|
sti _EM_PSIZE
|
||||||
|
|
|
@ -10,18 +10,18 @@
|
||||||
#define ENTRY_INC 10
|
#define ENTRY_INC 10
|
||||||
#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC)
|
#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC)
|
||||||
|
|
||||||
extern const char **_envp;
|
extern const char **_penvp;
|
||||||
extern const char **environ; /* environ is a shadow name for _envp */
|
extern const char **environ; /* environ is a shadow name for _penvp */
|
||||||
|
|
||||||
int
|
int
|
||||||
putenv(char *name)
|
putenv(char *name)
|
||||||
{
|
{
|
||||||
register const char **v = _envp;
|
register const char **v = _penvp;
|
||||||
register char *r;
|
register char *r;
|
||||||
static int size = 0;
|
static int size = 0;
|
||||||
/* When size != 0, it contains the number of entries in the
|
/* When size != 0, it contains the number of entries in the
|
||||||
* table (including the final NULL pointer). This means that the
|
* table (including the final NULL pointer). This means that the
|
||||||
* last non-null entry is _envp[size - 2].
|
* last non-null entry is _penvp[size - 2].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!name) return 0;
|
if (!name) return 0;
|
||||||
|
@ -48,7 +48,7 @@ putenv(char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*r = '=';
|
*r = '=';
|
||||||
v = _envp;
|
v = _penvp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!size) {
|
if (!size) {
|
||||||
|
@ -62,18 +62,18 @@ putenv(char *name)
|
||||||
if (!(v = malloc(rounded(i) * sizeof(char **))))
|
if (!(v = malloc(rounded(i) * sizeof(char **))))
|
||||||
return 1;
|
return 1;
|
||||||
size = i;
|
size = i;
|
||||||
p = _envp;
|
p = _penvp;
|
||||||
_envp = v;
|
_penvp = v;
|
||||||
while (*v++ = *p++); /* copy the environment */
|
while (*v++ = *p++); /* copy the environment */
|
||||||
v = _envp;
|
v = _penvp;
|
||||||
} else if (!(size % ENTRY_INC)) {
|
} else if (!(size % ENTRY_INC)) {
|
||||||
if (!(v = realloc(_envp, rounded(size) * sizeof(char **))))
|
if (!(v = realloc(_penvp, rounded(size) * sizeof(char **))))
|
||||||
return 1;
|
return 1;
|
||||||
_envp = v;
|
_penvp = v;
|
||||||
}
|
}
|
||||||
v[size - 1] = name;
|
v[size - 1] = name;
|
||||||
v[size] = NULL;
|
v[size] = NULL;
|
||||||
size++;
|
size++;
|
||||||
environ = _envp;
|
environ = _penvp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
extern const char **environ;
|
extern const char **_penvp;
|
||||||
|
|
||||||
char *
|
char *
|
||||||
getenv(const char *name)
|
getenv(const char *name)
|
||||||
{
|
{
|
||||||
register const char **v = environ;
|
register const char **v = _penvp;
|
||||||
register const char *p, *q;
|
register const char *p, *q;
|
||||||
|
|
||||||
if (v == NULL || name == NULL)
|
if (v == NULL || name == NULL)
|
||||||
|
|
|
@ -10,11 +10,19 @@
|
||||||
extern int _fork(void);
|
extern int _fork(void);
|
||||||
extern int _wait(int *);
|
extern int _wait(int *);
|
||||||
extern void _exit(int);
|
extern void _exit(int);
|
||||||
extern void _execl(char *, ...);
|
extern void _execve(const char *path, const char ** argv, const char ** envp);
|
||||||
extern void _close(int);
|
extern void _close(int);
|
||||||
|
|
||||||
#define FAIL 127
|
#define FAIL 127
|
||||||
|
|
||||||
|
extern const char **_penvp;
|
||||||
|
static const char *exec_tab[] = {
|
||||||
|
"sh", /* argv[0] */
|
||||||
|
"-c", /* argument to the shell */
|
||||||
|
NULL, /* to be filled with user command */
|
||||||
|
NULL /* terminating NULL */
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
system(const char *str)
|
system(const char *str)
|
||||||
{
|
{
|
||||||
|
@ -27,8 +35,9 @@ system(const char *str)
|
||||||
for (i = 3; i <= 20; i++)
|
for (i = 3; i <= 20; i++)
|
||||||
_close(i);
|
_close(i);
|
||||||
if (!str) str = "cd ."; /* just testing for a shell */
|
if (!str) str = "cd ."; /* just testing for a shell */
|
||||||
_execl("/bin/sh", "sh", "-c", str, (char *) NULL);
|
exec_tab[2] = str; /* fill in command */
|
||||||
/* get here if execl fails ... */
|
_execve("/bin/sh", exec_tab, _penvp);
|
||||||
|
/* get here if execve fails ... */
|
||||||
_exit(FAIL); /* see manual page */
|
_exit(FAIL); /* see manual page */
|
||||||
}
|
}
|
||||||
while ((waitval = _wait(&exitstatus)) != pid) {
|
while ((waitval = _wait(&exitstatus)) != pid) {
|
||||||
|
@ -39,7 +48,7 @@ system(const char *str)
|
||||||
exitstatus = -1;
|
exitstatus = -1;
|
||||||
}
|
}
|
||||||
if (!str) {
|
if (!str) {
|
||||||
if (exitstatus == FAIL << 8) /* execl() failed */
|
if (exitstatus == FAIL << 8) /* execve() failed */
|
||||||
exitstatus = 0;
|
exitstatus = 0;
|
||||||
else exitstatus = 1; /* /bin/sh exists */
|
else exitstatus = 1; /* /bin/sh exists */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue