[C++] Re-generate build.ninja when ckati is updated
diff --git a/fileutil.cc b/fileutil.cc
index eb4fc22..4c87e9c 100644
--- a/fileutil.cc
+++ b/fileutil.cc
@@ -23,6 +23,9 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#if defined(__APPLE__)
+#include <mach-o/dyld.h>
+#endif
 
 #include <unordered_map>
 
@@ -95,6 +98,26 @@
   abort();
 }
 
+void GetExecutablePath(string* path) {
+#if defined(__linux__)
+  char mypath[PATH_MAX + 1];
+  ssize_t l = readlink("/proc/self/exe", mypath, PATH_MAX);
+  if (l < 0) {
+    PERROR("readlink for /proc/self/exe");
+  }
+  mypath[l] = '\0';
+  *path = mypath;
+#elif defined(__APPLE__)
+  char mypath[PATH_MAX + 1];
+  if (_NSGetExecutablePath(mypath, PATH_MAX) != 0) {
+    ERROR("_NSGetExecutablePath failed");
+  }
+  *path = mypath;
+#else
+#error "Unsupported OS"
+#endif
+}
+
 namespace {
 
 class GlobCache {