Support finding executable dir on Darwin

QEMU searches for its datafiles in directories that are relative
to the executable directory. However, the function to find the
executable directory is currently not implemented on Darwin which
causes QEMU to fallback and look for the datafiles using absolute
paths which fails when using a prebuilt distribution.

Change-Id: Ibc67bf1fefbbca0fb62d4f209bffc27d32d59cca
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 062236a..802d466 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -45,6 +45,10 @@
 #include <sys/syscall.h>
 #endif
 
+#ifdef __APPLE__
+#include <libproc.h>
+#endif
+
 #ifdef __FreeBSD__
 #include <sys/sysctl.h>
 #include <sys/user.h>
@@ -336,7 +340,11 @@
 {
     char *dir;
     char *p = NULL;
+#if defined(__APPLE__)
+    char buf[PROC_PIDPATHINFO_MAXSIZE];
+#else
     char buf[PATH_MAX];
+#endif
 
     assert(!exec_dir[0]);
 
@@ -349,6 +357,14 @@
             p = buf;
         }
     }
+#elif defined(__APPLE__)
+    {
+        int len;
+        len = proc_pidpath(getpid(), buf, sizeof(buf));
+        if (len > 0) {
+            p = buf;
+        }
+    }
 #elif defined(__FreeBSD__) \
       || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME))
     {