Skip to content

Instantly share code, notes, and snippets.

@iwinux
Created July 8, 2012 19:02
Show Gist options
  • Save iwinux/3072340 to your computer and use it in GitHub Desktop.
Save iwinux/3072340 to your computer and use it in GitHub Desktop.
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