Merge pull request #230 from rubenllorente/master

Added OpenBSD support (2nd attempt)
This commit is contained in:
Con Kolivas 2022-06-26 20:25:09 +10:00 committed by GitHub
commit 7c079abb17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View file

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

26
lrzip.c
View file

@ -90,6 +90,32 @@ i64 get_ram(rzip_control *control)
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__ */
i64 get_ram(rzip_control *control)
{

View file

@ -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