10f66f451Sopenharmony_ci/* pwdx.c - report current directory of a process. 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com> 40f66f451Sopenharmony_ci 50f66f451Sopenharmony_ciUSE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciconfig PWDX 80f66f451Sopenharmony_ci bool "pwdx" 90f66f451Sopenharmony_ci default y 100f66f451Sopenharmony_ci help 110f66f451Sopenharmony_ci usage: pwdx PID... 120f66f451Sopenharmony_ci 130f66f451Sopenharmony_ci Print working directory of processes listed on command line. 140f66f451Sopenharmony_ci*/ 150f66f451Sopenharmony_ci 160f66f451Sopenharmony_ci#include "toys.h" 170f66f451Sopenharmony_ci 180f66f451Sopenharmony_civoid pwdx_main(void) 190f66f451Sopenharmony_ci{ 200f66f451Sopenharmony_ci char **optargs; 210f66f451Sopenharmony_ci 220f66f451Sopenharmony_ci for (optargs = toys.optargs; *optargs; optargs++) { 230f66f451Sopenharmony_ci char *path = toybuf; 240f66f451Sopenharmony_ci 250f66f451Sopenharmony_ci sprintf(toybuf, "/proc/%d/cwd", atoi(*optargs)); 260f66f451Sopenharmony_ci if (!readlink0(path, toybuf, sizeof(toybuf))) { 270f66f451Sopenharmony_ci path = strerror(errno); 280f66f451Sopenharmony_ci toys.exitval = 1; 290f66f451Sopenharmony_ci } 300f66f451Sopenharmony_ci 310f66f451Sopenharmony_ci xprintf("%s: %s\n", *optargs, path); 320f66f451Sopenharmony_ci } 330f66f451Sopenharmony_ci} 34