Use KERN_PROC_CWD on NetBSD, from Leonardo Taccari.

This commit is contained in:
Nicholas Marriott 2019-06-20 06:57:37 +01:00
parent ec151b79ec
commit b3ca410bc3

View File

@ -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);
}