Adding FreeBSD support
interkosmos opened this issue · comments
Please consider applying the following patch to code/zpl.h
in order to add support for FreeBSD 12. Might be necessary to polish it a little beforehand, as I am not a C expert.
--- zpl.h 2019-11-01 05:35:57.095504000 +0100
+++ zpl_new.h 2019-11-01 05:50:39.201436000 +0100
@@ -520,10 +520,16 @@
#include <stdlib.h> // NOTE: malloc on linux
#include <sys/mman.h>
-#if !defined(ZPL_SYSTEM_OSX)
+#if !defined(ZPL_SYSTEM_OSX) && !defined(ZPL_SYSTEM_FREEBSD)
#include <sys/sendfile.h>
#endif
+#if defined(ZPL_SYSTEM_FREEBSD)
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <sys/uio.h>
+#endif
+
#include <dirent.h>
#include <sys/stat.h>
#include <sys/time.h>
@@ -767,6 +773,11 @@
#endif
#endif
+#if defined(ZPL_SYSTEM_FREEBSD)
+ #define ZPL_EXTERN extern
+ #define zpl_inline inline
+#endif
+
#if !defined(zpl_no_inline)
#if defined(_MSC_VER)
#define zpl_no_inline __declspec(noinline)
@@ -1557,7 +1568,7 @@
zpl_isize threads_per_core;
} zpl_affinity;
-#elif defined(ZPL_SYSTEM_LINUX) || defined(ZPL_SYSTEM_EMSCRIPTEN)
+#elif defined(ZPL_SYSTEM_LINUX) || defined(ZPL_SYSTEM_FREEBSD) || defined(ZPL_SYSTEM_EMSCRIPTEN)
typedef struct zpl_affinity {
zpl_b32 is_accurate;
@@ -6967,7 +6978,7 @@
#else
-#if defined(ZPL_SYSTEM_LINUX)
+#if defined(ZPL_SYSTEM_LINUX) || defined(ZPL_SYSTEM_FREEBSD)
zpl_inline zpl_f64 zpl__unix_getime(void) {
struct timespec t;
zpl_f64 result;
@@ -8152,7 +8163,7 @@
return a->threads_per_core;
}
-#elif defined(ZPL_SYSTEM_LINUX)
+#elif defined(ZPL_SYSTEM_LINUX) || defined(ZPL_SYSTEM_FREEBSD)
// IMPORTANT TODO: This zpl_affinity stuff for linux needs be improved a lot!
// NOTE(zangent): I have to read /proc/cpuinfo to get the number of threads per core.
@@ -10816,7 +10827,11 @@
struct stat stat_existing;
fstat(existing_fd, &stat_existing);
+#if defined(ZPL_SYSTEM_FREEBSD)
+ size = sendfile(new_fd, existing_fd, 0, stat_existing.st_size, NULL, 0, 0);
+#else
size = sendfile(new_fd, existing_fd, 0, stat_existing.st_size);
+#endif
close(new_fd);
close(existing_fd);
Thank you for the patch, I will look into it.
Updated in a312bc0, let me know if there are any issues left.
Thank you, works.