Support FreeBSD

This commit is contained in:
Vanilla Hsu 2011-06-03 06:45:55 +02:00 committed by Ryan Dahl
parent ee712eba36
commit fb5262abdc
2 changed files with 21 additions and 0 deletions

View File

@ -3,3 +3,4 @@ Ryan Dahl <ryan@joyent.com>
Bert Belder <bertbelder@gmail.com>
Josh Roesslein <jroesslein@gmail.com>
Alan Gutierrez <alan@prettyrobots.com>
Vanilla Hsu <vanilla@fatpipi.com>

View File

@ -37,6 +37,10 @@
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
#endif
#if defined(__FreeBSD__)
#include <sys/sysctl.h>
#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");