diff options
author | Rob Landley <rob@landley.net> | 2013-09-02 05:06:05 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-09-02 05:06:05 -0500 |
commit | 23186636fcb261d263f417e605cbe8b7e2103ca5 (patch) | |
tree | 33212504f651622e72a600d813310df8069c6418 /toys | |
parent | 408d4f2670df910180988747f11b6290551ddaa7 (diff) | |
download | toybox-23186636fcb261d263f417e605cbe8b7e2103ca5.tar.gz |
pwdx by Lukasz Skalski.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/other/pwdx.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/toys/other/pwdx.c b/toys/other/pwdx.c new file mode 100644 index 00000000..c3f134f7 --- /dev/null +++ b/toys/other/pwdx.c @@ -0,0 +1,40 @@ +/* pwdx.c - report current directory of a process. + * + * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com> + +USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) + +config PWDX + bool "pwdx" + default y + help + usage: pwdx pids ... +*/ + +#include "toys.h" + +int pid_dir(char *pid) +{ + char *path; + int num_bytes; + + path = xmsprintf("/proc/%s/cwd",pid); + num_bytes = readlink(path,toybuf,sizeof(toybuf)); + if(num_bytes==-1){ + xprintf("%s: %s\n",pid,strerror(errno)); + return 1; + }else{ + toybuf[num_bytes]='\0'; + xprintf("%s: %s\n",pid,toybuf); + return 0; + } +} + +void pwdx_main(void) +{ + int i; + + for (i=0; toys.optargs[i]; i++) + toys.exitval |= pid_dir(toys.optargs[i]); +} + |