Skip to content

Commit

Permalink
Import sys/queue.h and sys/tree.h from FreeBSD and #include its
Browse files Browse the repository at this point in the history
instead of system ones when latter lacks some defines
It also allows building on MacOSX without installed kernel sources
  • Loading branch information
wulf7 committed Apr 27, 2015
1 parent 1550da6 commit dd0fb64
Show file tree
Hide file tree
Showing 12 changed files with 1,588 additions and 34 deletions.
35 changes: 8 additions & 27 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@

#include "config.h"

#ifdef BUILD_LIBRARY
#include <sys/types.h>

#ifdef HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#ifdef __APPLE__
#include </System/Library/Frameworks/Kernel.framework/Versions/Current/Headers/libkern/tree.h>
#else
#include "compat/queue.h"
#endif

#ifdef HAVE_SYS_TREE_H
#include <sys/tree.h> /* RB tree macroses */
#else
#include "compat/tree.h"
#endif

#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#endif /* BUILD_LIBRARY */
#include <pthread.h>

#ifdef BUILD_LIBRARY
#ifndef O_SYMLINK
#define O_SYMLINK O_NOFOLLOW
#endif
Expand All @@ -52,26 +55,6 @@
#define DTTOIF(dirtype) ((dirtype) << 12)
#endif

#ifndef SLIST_FOREACH_SAFE
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST((head)); \
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
(var) = (tvar))
#endif
#ifndef SLIST_REMOVE_AFTER
#define SLIST_REMOVE_AFTER(elm, field) do { \
SLIST_NEXT(elm, field) = \
SLIST_NEXT(SLIST_NEXT(elm, field), field); \
} while (0)
#endif
#ifndef RB_FOREACH_SAFE
#define RB_FOREACH_SAFE(x, name, head, y) \
for ((x) = RB_MIN(name, head); \
((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \
(x) = (y))
#endif
#endif /* BUILD_LIBRARY */

#ifndef HAVE_PTHREAD_BARRIER
typedef struct {
int count; /* the number of threads to wait on a barrier */
Expand All @@ -92,7 +75,6 @@ void pthread_barrier_wait (pthread_barrier_t *impl);
void pthread_barrier_destroy (pthread_barrier_t *impl);
#endif

#ifdef BUILD_LIBRARY
#ifndef AT_FDCWD
#define AT_FDCWD -100
#endif
Expand All @@ -113,6 +95,5 @@ DIR *fdopendir (int fd);
#ifndef HAVE_FSTATAT
int fstatat (int fd, const char *path, struct stat *buf, int flag);
#endif
#endif /* BUILD_LIBRARY */

#endif /* __COMPAT_H__ */
Loading

0 comments on commit dd0fb64

Please sign in to comment.