From 2c50a224f8c4b716299c4696957959a238f8d794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Llorente?= Date: Sun, 26 Jun 2022 12:07:40 +0200 Subject: [PATCH] Added OpenBSD support --- Lrzip.h | 4 ++++ lrzip.c | 26 ++++++++++++++++++++++++++ lrzip_private.h | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Lrzip.h b/Lrzip.h index 8934c59..7c98998 100644 --- a/Lrzip.h +++ b/Lrzip.h @@ -29,6 +29,10 @@ # include #endif +#if defined (__OpenBSD__) || (__NetBSD__) +# include +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/lrzip.c b/lrzip.c index 3d55db8..bcc04ce 100644 --- a/lrzip.c +++ b/lrzip.c @@ -90,6 +90,32 @@ i64 get_ram(rzip_control *control) return ramsize; } +#elif defined(__OpenBSD__) +# include +i64 get_ram(rzip_control *control) +{ + struct rlimit rl; + i64 ramsize = (i64)sysconf(_SC_PHYS_PAGES) * PAGE_SIZE; + + /* Raise limits all the way to the max */ + + if (getrlimit(RLIMIT_DATA, &rl) == -1) + fatal_return(("Failed to get limits in get_ram\n"), -1); + + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_DATA, &rl) == -1) + fatal_return(("Failed to set limits in get_ram\n"), -1); + + /* Declare detected RAM to be either the max RAM available from + physical memory or the max RAM allowed by RLIMIT_DATA, whatever + is smaller, to prevent the heuristics from selecting + compression windows which cause lrzip to go into deep swap */ + + if (rl.rlim_max < ramsize) + return rl.rlim_max; + + return ramsize; +} #else /* __APPLE__ */ i64 get_ram(rzip_control *control) { diff --git a/lrzip_private.h b/lrzip_private.h index 67ba247..035c529 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -144,7 +144,7 @@ extern int errno; #define unlikely(x) __builtin_expect(!!(x), 0) #define __maybe_unused __attribute__((unused)) -#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__ANDROID__) || defined(__APPLE__) +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__ANDROID__) || defined(__APPLE__) || defined(__OpenBSD__) # define ffsll __builtin_ffsll #endif