diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index e28e43a86..5f7feefe4 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -70,6 +70,9 @@ macro(detectOS) add_compile_definitions(OS_WEB) elseif (UNIX AND NOT APPLE) add_compile_definitions(OS_LINUX) + if (BSD AND BSD STREQUAL "FreeBSD") + add_compile_definitions(OS_FREEBSD) + endif() include(GNUInstallDirs) if(IMHEX_PLUGINS_IN_SHARE) diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 519ec6005..9270c414c 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -663,7 +663,11 @@ namespace hex { #if defined(OS_WINDOWS) return "Windows"; #elif defined(OS_LINUX) - return "Linux"; + #if defined(OS_FREEBSD) + return "FreeBSD"; + #else + return "Linux"; + #endif #elif defined(OS_MACOS) return "macOS"; #elif defined(OS_WEB) diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 7a4364cf0..2027fa771 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -13,7 +13,11 @@ #include #elif defined(OS_LINUX) || defined(OS_WEB) #include +# if defined(OS_FREEBSD) + #include +# else #include +# endif #endif #if defined(OS_WEB) diff --git a/plugins/builtin/include/content/providers/process_memory_provider.hpp b/plugins/builtin/include/content/providers/process_memory_provider.hpp index 0869a86ce..53c024dcc 100644 --- a/plugins/builtin/include/content/providers/process_memory_provider.hpp +++ b/plugins/builtin/include/content/providers/process_memory_provider.hpp @@ -1,6 +1,6 @@ #pragma once -#if defined(OS_WINDOWS) || defined (OS_LINUX) +#if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD)) #include #include diff --git a/plugins/builtin/source/content/providers.cpp b/plugins/builtin/source/content/providers.cpp index 513a23b04..618d2bfe2 100644 --- a/plugins/builtin/source/content/providers.cpp +++ b/plugins/builtin/source/content/providers.cpp @@ -37,7 +37,7 @@ namespace hex::plugin::builtin { ContentRegistry::Provider::add(false); ContentRegistry::Provider::add(false); - #if defined(OS_WINDOWS) ||defined (OS_LINUX) + #if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD)) ContentRegistry::Provider::add(); #endif diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index db94a75f6..2920fab49 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -28,7 +28,9 @@ #elif defined(OS_LINUX) #include #include - #include + #if !defined(OS_FREEBSD) + #include + #endif #include #include #include @@ -41,8 +43,11 @@ #include #endif -#if defined(OS_LINUX) -#define lseek lseek64 +#if defined(OS_LINUX) && !defined(OS_FREEBSD) + #define lseek lseek64 +#elif defined(OS_FREEBSD) + #include + #define DEFAULT_SECTOR_SIZE 512 #endif namespace hex::plugin::builtin { @@ -83,6 +88,12 @@ namespace hex::plugin::builtin { return -1; return 0; } + #elif defined(OS_FREEBSD) && defined(DIOCGSECTORSIZE) + int blkdev_get_sector_size(int fd, int *sector_size) { + if (ioctl(fd, DIOCGSECTORSIZE, sector_size) < 0) + return -1; + return 0; + } #else int blkdev_get_sector_size(int fd, int *sector_size) { (void)fd; @@ -97,6 +108,12 @@ namespace hex::plugin::builtin { return -1; return 0; } + #elif defined(OS_FREEBSD) && defined(DIOCGMEDIASIZE) + int blkdev_get_size(int fd, u64 *bytes) { + if (ioctl(fd, DIOCGMEDIASIZE, bytes) < 0) + return -1; + return 0; + } #else int blkdev_get_size(int fd, u64 *bytes) { struct stat st; diff --git a/plugins/builtin/source/content/providers/process_memory_provider.cpp b/plugins/builtin/source/content/providers/process_memory_provider.cpp index 8cee45d2f..a532181d2 100644 --- a/plugins/builtin/source/content/providers/process_memory_provider.cpp +++ b/plugins/builtin/source/content/providers/process_memory_provider.cpp @@ -1,4 +1,4 @@ -#if defined(OS_WINDOWS) || defined (OS_LINUX) +#if defined(OS_WINDOWS) || (defined(OS_LINUX) && !defined(OS_FREEBSD)) #include