Created
July 8, 2012 19:02
-
-
Save iwinux/3072340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/osdep-darwin.c b/osdep-darwin.c | |
index c5820df..7b15446 100644 | |
--- a/osdep-darwin.c | |
+++ b/osdep-darwin.c | |
@@ -18,6 +18,7 @@ | |
#include <sys/types.h> | |
#include <sys/sysctl.h> | |
+#include <libproc.h> | |
#include <event.h> | |
#include <stdlib.h> | |
@@ -52,6 +53,15 @@ | |
char * | |
osdep_get_cwd(pid_t pid) | |
{ | |
+ static char wd[PATH_MAX]; | |
+ struct proc_vnodepathinfo pathinfo; | |
+ int ret; | |
+ | |
+ ret = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof(pathinfo)); | |
+ if (ret == sizeof(pathinfo)) { | |
+ strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof(wd)); | |
+ return (wd); | |
+ } | |
return (NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment