aboutsummaryrefslogtreecommitdiff
path: root/toys/other/pwdx.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-06-15 15:47:01 -0500
committerRob Landley <rob@landley.net>2016-06-15 15:47:01 -0500
commit46409d50e5632b28b88cfa4991fffef9adaa490d (patch)
tree4c3347b37664b580996e4551bde023346567728b /toys/other/pwdx.c
parent97ddc600c95623bf803eac4f2a4deda2a2db02d4 (diff)
downloadtoybox-46409d50e5632b28b88cfa4991fffef9adaa490d.tar.gz
Add readlink0() and readlinkat0() which null terminate the data.
Diffstat (limited to 'toys/other/pwdx.c')
-rw-r--r--toys/other/pwdx.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/toys/other/pwdx.c b/toys/other/pwdx.c
index bde16e79..2a72dba3 100644
--- a/toys/other/pwdx.c
+++ b/toys/other/pwdx.c
@@ -20,20 +20,14 @@ void pwdx_main(void)
char **optargs;
for (optargs = toys.optargs; *optargs; optargs++) {
- char *path;
- int num_bytes;
+ char *path = toybuf;
- path = xmprintf("/proc/%s/cwd", *optargs);
- num_bytes = readlink(path, toybuf, sizeof(toybuf)-1);
- free(path);
-
- if (num_bytes==-1) {
+ sprintf(toybuf, "/proc/%d/cwd", atoi(*optargs));
+ if (!readlink0(path, toybuf, sizeof(toybuf))) {
path = strerror(errno);
toys.exitval = 1;
- } else {
- path = toybuf;
- toybuf[num_bytes] = 0;
}
+
xprintf("%s: %s\n", *optargs, path);
}
}