Mercurial > hg > toybox
changeset 1038:5b6027634d01 draft
pwdx by Lukasz Skalski.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 02 Sep 2013 05:06:05 -0500 |
parents | af1780148f7c |
children | 75f5e63d79c3 |
files | toys/other/pwdx.c |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toys/other/pwdx.c Mon Sep 02 05:06:05 2013 -0500 @@ -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]); +} +