pwdx.c revision 6db8529a785e2cab142e840b6e3fbdcc2c02dd1f
1/* pwdx.c - report current directory of a process. 2 * 3 * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com> 4 5USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) 6 7config PWDX 8 bool "pwdx" 9 default y 10 help 11 usage: pwdx PID... 12 13 Print working directory of processes listed on command line. 14*/ 15 16#include "toys.h" 17 18void pwdx_main(void) 19{ 20 char **optargs; 21 22 for (optargs = toys.optargs; *optargs; optargs++) { 23 char *path; 24 int num_bytes; 25 26 path = xmsprintf("/proc/%s/cwd", *optargs); 27 num_bytes = readlink(path, toybuf, sizeof(toybuf)-1); 28 free(path); 29 30 if (num_bytes==-1) { 31 path = strerror(errno); 32 toys.exitval = 1; 33 } else { 34 path = toybuf; 35 toybuf[num_bytes] = 0; 36 } 37 xprintf("%s: %s\n", *optargs, path); 38 } 39} 40