mirror of
https://github.com/uselessd/alcove.git
synced 2026-04-15 17:25:33 +00:00
Add environ(7), clearenv(3)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
chdir/1
|
||||
chroot/1
|
||||
clearenv/0
|
||||
clone/1
|
||||
clone_define/1
|
||||
environ/0
|
||||
execve/3
|
||||
execvp/2
|
||||
exit/1
|
||||
|
||||
@@ -15,6 +15,24 @@
|
||||
#include "alcove.h"
|
||||
#include "alcove_call.h"
|
||||
|
||||
extern char **environ;
|
||||
|
||||
/*
|
||||
* environ(7)
|
||||
*
|
||||
*/
|
||||
ETERM *
|
||||
alcove_environ(alcove_state_t *ap, ETERM *arg)
|
||||
{
|
||||
char **envp = environ;
|
||||
ETERM *t = erl_mk_empty_list();
|
||||
|
||||
for ( ; envp && *envp; envp++)
|
||||
t = erl_cons(erl_mk_binary(*envp, strlen(*envp)), t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*
|
||||
* getenv(3)
|
||||
*
|
||||
@@ -146,3 +164,27 @@ BADARG:
|
||||
erl_free(name);
|
||||
return erl_mk_atom("badarg");
|
||||
}
|
||||
|
||||
/*
|
||||
* clearenv(3)
|
||||
*
|
||||
*/
|
||||
ETERM *
|
||||
alcove_clearenv(alcove_state_t *ap, ETERM *arg)
|
||||
{
|
||||
#ifdef __linux__
|
||||
int rv = 0;
|
||||
int errnum = 0;
|
||||
|
||||
rv = clearenv();
|
||||
|
||||
errnum = errno;
|
||||
|
||||
return (rv < 0)
|
||||
? alcove_errno(errnum)
|
||||
: erl_mk_atom("ok");
|
||||
#else
|
||||
environ = NULL;
|
||||
return erl_mk_atom("ok");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -170,6 +170,10 @@ env({_, Port, Child}) ->
|
||||
Reply5 = alcove:unsetenv(Port, [Child], "ALCOVE"),
|
||||
Reply6 = alcove:getenv(Port, [Child], "ALCOVE"),
|
||||
|
||||
Reply7 = alcove:environ(Port, [Child]),
|
||||
Reply8 = alcove:clearenv(Port, [Child]),
|
||||
Reply9 = alcove:environ(Port, [Child]),
|
||||
|
||||
[
|
||||
?_assertEqual(false, Reply0),
|
||||
?_assertEqual(ok, Reply1),
|
||||
@@ -177,7 +181,11 @@ env({_, Port, Child}) ->
|
||||
?_assertEqual(ok, Reply3),
|
||||
?_assertEqual(<<"abcd">>, Reply4),
|
||||
?_assertEqual(ok, Reply5),
|
||||
?_assertEqual(false, Reply6)
|
||||
?_assertEqual(false, Reply6),
|
||||
|
||||
?_assertNotEqual(0, length(Reply7)),
|
||||
?_assertEqual(ok, Reply8),
|
||||
?_assertEqual(0, length(Reply9))
|
||||
].
|
||||
|
||||
setns({{unix,linux}, Port, Child}) ->
|
||||
|
||||
Reference in New Issue
Block a user