aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2015-06-03 11:20:08 -0700
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2015-06-03 11:20:08 -0700
commit96f1d4ada222cbcbea972ee2ac3d20f16bd87ac3 (patch)
tree0f5a6c8b67d360f9f6577525bb95f7a012bec2eb /src
parentdbcfc5e2021fe70ce9e8d5bfda4e7a2df08a2130 (diff)
parent0af3ed5189182985573dbea30e173aca0f9a1685 (diff)
Merge pull request #453 from bakineggs/master
Add protoc path detection for Mac OS
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 667b2b63..c57cfd3d 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -53,6 +53,10 @@
#include <google/protobuf/stubs/shared_ptr.h>
#endif
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/compiler/importer.h>
@@ -186,6 +190,16 @@ bool GetProtocAbsolutePath(string* path) {
#ifdef _WIN32
char buffer[MAX_PATH];
int len = GetModuleFileName(NULL, buffer, MAX_PATH);
+#elif __APPLE__
+ char buffer[PATH_MAX];
+ int len = 0;
+
+ char dirtybuffer[PATH_MAX];
+ uint32_t size = sizeof(dirtybuffer);
+ if (_NSGetExecutablePath(dirtybuffer, &size) == 0) {
+ realpath(dirtybuffer, buffer);
+ len = strlen(buffer);
+ }
#else
char buffer[PATH_MAX];
int len = readlink("/proc/self/exe", buffer, PATH_MAX);