diff --git a/AUTHORS b/AUTHORS index 7cfecd0d..47b47d29 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,3 +3,4 @@ Ryan Dahl Bert Belder Josh Roesslein Alan Gutierrez +Vanilla Hsu diff --git a/uv-unix.c b/uv-unix.c index d10e0de0..0b032436 100644 --- a/uv-unix.c +++ b/uv-unix.c @@ -37,6 +37,10 @@ #include /* _NSGetExecutablePath */ #endif +#if defined(__FreeBSD__) +#include +#endif + static uv_err_t last_err; static uv_alloc_cb alloc_cb; @@ -1233,6 +1237,22 @@ int uv_get_exepath(char* buffer, size_t* size) { *size = readlink("/proc/self/exe", buffer, *size - 1); if (*size <= 0) return -1; buffer[*size] = '\0'; + return 0; +#elif defined(__FreeBSD__) + int mib[4]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + + size_t cb = *size; + if (sysctl(mib, 4, buffer, &cb, NULL, 0) < 0) { + *size = 0; + return -1; + } + *size = strlen(buffer); + return 0; #else assert(0 && "implement me");