Added OpenBSD support

This commit is contained in:
Rubén Llorente 2022-06-26 12:07:40 +02:00
parent 3495188cd8
commit 2c50a224f8
3 changed files with 31 additions and 1 deletions

View file

@ -29,6 +29,10 @@
# include <inttypes.h> # include <inttypes.h>
#endif #endif
#if defined (__OpenBSD__) || (__NetBSD__)
# include <stdarg.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

26
lrzip.c
View file

@ -90,6 +90,32 @@ i64 get_ram(rzip_control *control)
return ramsize; return ramsize;
} }
#elif defined(__OpenBSD__)
# include <sys/resource.h>
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__ */ #else /* __APPLE__ */
i64 get_ram(rzip_control *control) i64 get_ram(rzip_control *control)
{ {

View file

@ -144,7 +144,7 @@ extern int errno;
#define unlikely(x) __builtin_expect(!!(x), 0) #define unlikely(x) __builtin_expect(!!(x), 0)
#define __maybe_unused __attribute__((unused)) #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 # define ffsll __builtin_ffsll
#endif #endif