osdep_get_cwd for NetBSD, from Leonardo Taccari.

This commit is contained in:
Nicholas Marriott 2018-11-29 10:37:27 +00:00
parent 1ed994a6c8
commit 6cf2f74fe9

View File

@ -23,10 +23,13 @@
#include <errno.h> #include <errno.h>
#include <event.h> #include <event.h>
#include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "tmux.h"
#define is_runnable(p) \ #define is_runnable(p) \
((p)->p_stat == LSRUN || (p)->p_stat == SIDL) ((p)->p_stat == LSRUN || (p)->p_stat == SIDL)
#define is_stopped(p) \ #define is_stopped(p) \
@ -129,6 +132,22 @@ error:
char * char *
osdep_get_cwd(int fd) osdep_get_cwd(int fd)
{ {
static char target[PATH_MAX + 1];
char *path;
pid_t pgrp;
ssize_t n;
if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL);
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
n = readlink(path, target, sizeof(target) - 1);
free(path);
if (n > 0) {
target[n] = '\0';
return (target);
}
return (NULL); return (NULL);
} }