Mercurial > hg > toybox
annotate toys/other/pwdx.c @ 1776:7bf68329eb3b draft default tip
Repository switched to git at https://github.com/landley/toybox
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Apr 2015 02:28:32 -0500 |
parents | 0752b2d58909 |
children |
rev | line source |
---|---|
1038 | 1 /* pwdx.c - report current directory of a process. |
2 * | |
3 * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com> | |
4 | |
5 USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) | |
6 | |
7 config PWDX | |
8 bool "pwdx" | |
9 default y | |
10 help | |
1039 | 11 usage: pwdx PID... |
12 | |
13 Print working directory of processes listed on command line. | |
1038 | 14 */ |
15 | |
16 #include "toys.h" | |
17 | |
1039 | 18 void pwdx_main(void) |
1038 | 19 { |
1150
ac4a0cde89c2
Don't permute toys.optargs, cleanup code (xexec()) can free it.
Rob Landley <rob@landley.net>
parents:
1039
diff
changeset
|
20 char **optargs; |
ac4a0cde89c2
Don't permute toys.optargs, cleanup code (xexec()) can free it.
Rob Landley <rob@landley.net>
parents:
1039
diff
changeset
|
21 |
ac4a0cde89c2
Don't permute toys.optargs, cleanup code (xexec()) can free it.
Rob Landley <rob@landley.net>
parents:
1039
diff
changeset
|
22 for (optargs = toys.optargs; *optargs; optargs++) { |
1039 | 23 char *path; |
24 int num_bytes; | |
1038 | 25 |
1183
0752b2d58909
Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents:
1150
diff
changeset
|
26 path = xmprintf("/proc/%s/cwd", *optargs); |
1039 | 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 } | |
1150
ac4a0cde89c2
Don't permute toys.optargs, cleanup code (xexec()) can free it.
Rob Landley <rob@landley.net>
parents:
1039
diff
changeset
|
37 xprintf("%s: %s\n", *optargs, path); |
1038 | 38 } |
39 } |