aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-09-02 18:48:59 -0500
committerRob Landley <rob@landley.net>2013-09-02 18:48:59 -0500
commit7f8f9ec5113bff8c0f7bd3e9341b688d8af91258 (patch)
tree5fdfee8e952518d19be2ff3625029817a8c381cd
parent23186636fcb261d263f417e605cbe8b7e2103ca5 (diff)
downloadtoybox-7f8f9ec5113bff8c0f7bd3e9341b688d8af91258.tar.gz
Cleanup pwdx
-rw-r--r--toys/other/pwdx.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/toys/other/pwdx.c b/toys/other/pwdx.c
index c3f134f7..5be49d62 100644
--- a/toys/other/pwdx.c
+++ b/toys/other/pwdx.c
@@ -8,33 +8,30 @@ config PWDX
bool "pwdx"
default y
help
- usage: pwdx pids ...
+ usage: pwdx PID...
+
+ Print working directory of processes listed on command line.
*/
#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]);
+ for (; *toys.optargs; toys.optargs++) {
+ char *path;
+ int num_bytes;
+
+ path = xmsprintf("/proc/%s/cwd", *toys.optargs);
+ num_bytes = readlink(path, toybuf, sizeof(toybuf)-1);
+ free(path);
+
+ if (num_bytes==-1) {
+ path = strerror(errno);
+ toys.exitval = 1;
+ } else {
+ path = toybuf;
+ toybuf[num_bytes] = 0;
+ }
+ xprintf("%s: %s\n", *toys.optargs, path);
+ }
}
-