| ... | ... | @@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t; |
| 50 | 50 | |
| 51 | 51 | #endif |
| 52 | 52 | |
| 53 | | #if defined(ZIG_OS_LINUX) |
| 53 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 54 | 54 | #include <link.h> |
| 55 | 55 | #endif |
| 56 | 56 | |
| 57 | #if defined(ZIG_OS_FREEBSD) |
| 58 | #include <sys/sysctl.h> |
| 59 | #endif |
| 57 | 60 | |
| 58 | 61 | #if defined(__MACH__) |
| 59 | 62 | #include <mach/clock.h> |
| ... | ... | @@ -75,7 +78,9 @@ static clock_serv_t cclock; |
| 75 | 78 | #if defined(__APPLE__) && !defined(environ) |
| 76 | 79 | #include <crt_externs.h> |
| 77 | 80 | #define environ (*_NSGetEnviron()) |
| 78 | | #endif |
| 81 | #elif defined(ZIG_OS_FREEBSD) |
| 82 | extern char **environ; |
| 83 | #endif |
| 79 | 84 | |
| 80 | 85 | #if defined(ZIG_OS_POSIX) |
| 81 | 86 | static void populate_termination(Termination *term, int status) { |
| ... | ... | @@ -1442,6 +1447,15 @@ Error os_self_exe_path(Buf *out_path) { |
| 1442 | 1447 | } |
| 1443 | 1448 | buf_resize(out_path, amt); |
| 1444 | 1449 | return ErrorNone; |
| 1450 | #elif defined(ZIG_OS_FREEBSD) |
| 1451 | buf_resize(out_path, PATH_MAX); |
| 1452 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
| 1453 | size_t cb = PATH_MAX; |
| 1454 | if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) { |
| 1455 | return ErrorUnexpected; |
| 1456 | } |
| 1457 | buf_resize(out_path, cb); |
| 1458 | return ErrorNone; |
| 1445 | 1459 | #endif |
| 1446 | 1460 | return ErrorFileNotFound; |
| 1447 | 1461 | } |
| ... | ... | @@ -1747,7 +1761,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1747 | 1761 | buf_resize(out_path, 0); |
| 1748 | 1762 | buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname); |
| 1749 | 1763 | return ErrorNone; |
| 1750 | | #elif defined(ZIG_OS_LINUX) |
| 1764 | #elif defined(ZIG_OS_POSIX) |
| 1751 | 1765 | const char *home_dir = getenv("HOME"); |
| 1752 | 1766 | if (home_dir == nullptr) { |
| 1753 | 1767 | // TODO use /etc/passwd |
| ... | ... | @@ -1760,7 +1774,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1760 | 1774 | } |
| 1761 | 1775 | |
| 1762 | 1776 | |
| 1763 | | #if defined(ZIG_OS_LINUX) |
| 1777 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1764 | 1778 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { |
| 1765 | 1779 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); |
| 1766 | 1780 | if (info->dlpi_name[0] == '/') { |
| ... | ... | @@ -1771,7 +1785,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, |
| 1771 | 1785 | #endif |
| 1772 | 1786 | |
| 1773 | 1787 | Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { |
| 1774 | | #if defined(ZIG_OS_LINUX) |
| 1788 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1775 | 1789 | paths.resize(0); |
| 1776 | 1790 | dl_iterate_phdr(self_exe_shared_libs_callback, &paths); |
| 1777 | 1791 | return ErrorNone; |
| ... | ... | @@ -1940,7 +1954,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { |
| 1940 | 1954 | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; |
| 1941 | 1955 | mtime->nsec = 0; |
| 1942 | 1956 | return ErrorNone; |
| 1943 | | #elif defined(ZIG_OS_LINUX) |
| 1957 | #elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1944 | 1958 | struct stat statbuf; |
| 1945 | 1959 | if (fstat(file, &statbuf) == -1) |
| 1946 | 1960 | return ErrorFileSystem; |