diff --git a/bin/alcove.escript b/bin/alcove.escript index 89e0821..2233d11 100755 --- a/bin/alcove.escript +++ b/bin/alcove.escript @@ -254,6 +254,7 @@ specs() -> -spec chdir(port(),iodata()) -> 'ok' | {'error', file:posix()}. -spec chroot(port(),iodata()) -> 'ok' | {'error', file:posix()}. -spec execvp(port(),iodata(),iodata()) -> 'ok'. +-spec getcwd(port()) -> {'ok', binary()} | {'error', file:posix()}. -spec getgid(port()) -> non_neg_integer(). -spec getrlimit(port(),non_neg_integer()) -> {'ok', #rlimit{}} | {'error', file:posix()}. -spec getuid(port()) -> non_neg_integer(). diff --git a/c_src/alcove_cmd.c b/c_src/alcove_cmd.c index 2adc137..625b2ee 100644 --- a/c_src/alcove_cmd.c +++ b/c_src/alcove_cmd.c @@ -170,6 +170,21 @@ BADARG: return erl_mk_atom("badarg"); } +/* + * getcwd(3) + * + */ + static ETERM * +alcove_getcwd(ETERM *arg) +{ + char buf[PATH_MAX] = {0}; + + if (!getcwd(buf, sizeof(buf))) + return alcove_errno(errno); + + return alcove_ok(erl_mk_binary(buf, strlen(buf))); +} + /* * getgid(2) * diff --git a/c_src/alcove_cmd.proto b/c_src/alcove_cmd.proto index a29a00f..b7952ed 100644 --- a/c_src/alcove_cmd.proto +++ b/c_src/alcove_cmd.proto @@ -1,6 +1,7 @@ chdir/1 chroot/1 execvp/2 +getcwd/0 getgid/0 getrlimit/1 getuid/0