Unverified Commit d48f526d authored by Artemis Tosini's avatar Artemis Tosini
Browse files

openbsd.{compat,compatHook}: init

OpenBSD does not provide a compatibility library for running
build tools on other OSes, but we still need one.
`openbsd.compat` inspired by the `freebsd.compat` package and provides
a header-only compatibility layer that can be used across multiple
openbsd build packages. The source is included in the nixpkgs tree
because it functions similarly to per-package patches.

`openbsd.compatHook` provides a build hook that can be added into
`extraNativeBuildInputs` to include `compat` in the library search
path as a system library.
parent 51a07b20
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
#pragma once
#include_next <err.h>

#include <errno.h>
#include <stdarg.h>
static inline void __attribute__((__format__(printf, 3, 4)))
errc(int eval, int code, const char *fmt, ...) {
  // verr uses the error code from errno
  // No need to keep the old value since this is noreturn anyway
  errno = code;

  va_list args;
  va_start(args, fmt);
  verr(eval, fmt, args);
  va_end(args);
}

static inline void __attribute__((__format__(printf, 2, 3)))
warnc(int code, const char *fmt, ...) {
  // verr uses the error code from errno
  int old_errno = errno;
  errno = code;

  va_list args;
  va_start(args, fmt);
  vwarn(fmt, args);
  va_end(args);

  errno = old_errno;
}
+6 −0
Original line number Diff line number Diff line
#pragma once
#include_next <fcntl.h>

// Linux doesn't let you lock during open, make these do nothing
#define O_EXLOCK 0
#define O_SHLOCK 0
+4 −0
Original line number Diff line number Diff line
#include_next <sys/cdefs.h>

#define __packed __attribute__((__packed__))
#define __aligned(x) __attribute__((__aligned__(x)))
+1 −0
Original line number Diff line number Diff line
#include <dirent.h>
+2 −0
Original line number Diff line number Diff line
// Seems to be the only header for htonl
#include <netinet/in.h>
Loading