Skip to content

Commit

Permalink
Fix finding google/protobuf/descriptor.proto on FreeBSD (#7954)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxrmorozov committed Oct 22, 2020
1 parent 151d494 commit 2558c5d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@

#include <memory>

#ifdef __APPLE__
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#elif defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif

#include <google/protobuf/stubs/common.h>
Expand Down Expand Up @@ -202,6 +204,13 @@ bool GetProtocAbsolutePath(std::string* path) {
realpath(dirtybuffer, buffer);
len = strlen(buffer);
}
#elif defined(__FreeBSD__)
char buffer[PATH_MAX];
size_t len = PATH_MAX;
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
if (sysctl(mib, 4, &buffer, &len, NULL, 0) != 0) {
len = 0;
}
#else
char buffer[PATH_MAX];
int len = readlink("/proc/self/exe", buffer, PATH_MAX);
Expand Down

0 comments on commit 2558c5d

Please sign in to comment.