summaryrefslogtreecommitdiffstats
path: root/osdep-netbsd.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2019-06-20 06:57:37 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2019-06-20 06:57:37 +0100
commitb3ca410bc398e9aa7a045cf1337ca3f08c005e6e (patch)
tree95554efce3a12aa501658457e6707a5f683c78db /osdep-netbsd.c
parentec151b79ec672fac04db3305a161bcd67e22bbb7 (diff)
Use KERN_PROC_CWD on NetBSD, from Leonardo Taccari.
Diffstat (limited to 'osdep-netbsd.c')
-rw-r--r--osdep-netbsd.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/osdep-netbsd.c b/osdep-netbsd.c
index daca1abb..67894175 100644
--- a/osdep-netbsd.c
+++ b/osdep-netbsd.c
@@ -133,13 +133,27 @@ char *
osdep_get_cwd(int fd)
{
static char target[PATH_MAX + 1];
- char *path;
pid_t pgrp;
+#ifdef KERN_PROC_CWD
+ int mib[4];
+ size_t len;
+#else
+ char *path;
ssize_t n;
+#endif
if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL);
+#ifdef KERN_PROC_CWD
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC_ARGS;
+ mib[2] = pgrp;
+ mib[3] = KERN_PROC_CWD;
+ len = sizeof(target);
+ if (sysctl(mib, __arraycount(mib), target, &len, NULL, 0) == 0)
+ return (target);
+#else
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
n = readlink(path, target, sizeof(target) - 1);
free(path);
@@ -147,6 +161,7 @@ osdep_get_cwd(int fd)
target[n] = '\0';
return (target);
}
+#endif
return (NULL);
}