build: Added support patches for FreeBSD (#1584)

This pull request fixes build on FreeBSD. The changes are conditioned
with `#if defined(__FreeBSD__)` preprocessor macro and they should not
affect build for other operating systems.

---------

Co-authored-by: Nik <werwolv98@gmail.com>
Co-authored-by: iTrooz <hey@itrooz.fr>
This commit is contained in:
Nobutaka Mantani
2024-03-22 05:31:17 +09:00
committed by WerWolv
parent 27f3c634ba
commit 70b9ceba72
7 changed files with 35 additions and 7 deletions

View File

@@ -28,7 +28,9 @@
#elif defined(OS_LINUX)
#include <fcntl.h>
#include <unistd.h>
#include <linux/fs.h>
#if !defined(OS_FREEBSD)
#include <linux/fs.h>
#endif
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@@ -41,8 +43,11 @@
#include <sys/disk.h>
#endif
#if defined(OS_LINUX)
#define lseek lseek64
#if defined(OS_LINUX) && !defined(OS_FREEBSD)
#define lseek lseek64
#elif defined(OS_FREEBSD)
#include <sys/disk.h>
#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;