Skip to content

Commit

Permalink
Merge pull request #186 from Al2Klimov/openbsd
Browse files Browse the repository at this point in the history
Support OpenBSD
  • Loading branch information
AltraMayor authored Oct 24, 2022
2 parents 57448c9 + bca777b commit 3b015a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,18 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice)
}
}

#endif /* Apple Macintosh */

#if (__APPLE__ && __MACH__) || defined(__OpenBSD__)

#include <unistd.h> /* For usleep(). */

void msleep(double wait_ms)
{
assert(!usleep(wait_ms * 1000));
}

#else
#else /* Apple Macintosh / OpenBSD */

#include <time.h> /* For clock_gettime() and clock_nanosleep(). */

Expand Down Expand Up @@ -254,4 +258,4 @@ void msleep(double wait_ms)
assert(ret == 0);
}

#endif
#endif /* Apple Macintosh / OpenBSD */
16 changes: 16 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice);
#define fdatasync(fd) fsync(fd)
#endif

#ifdef __OpenBSD__

#define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
#define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */

/*
* OpenBSD doesn't have posix_fadvise() (...).
* There is some code [in F3] to emulate posix_fadvise for MacOS
* but it uses various fcntl(2) commands that we don't have [in OpenBSD].
*
* -- Stuart Henderson, OpenBSD developer
*/
#define posix_fadvise(fd, offset, len, advice) (0)

#endif /* OpenBSD */

#endif /* HEADER_UTILS_H */

0 comments on commit 3b015a5

Please sign in to comment.