aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-18 22:50:51 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-18 22:50:51 +0200
commit39c4979dec4465d704aca3a1e4ad12c4bda578d4 (patch)
tree170afdd3d011361eb2a7d4af0bca349c0bf582db
parent0c43120437a3a4cca4cdbb1b0d23b4088a5cba1a (diff)
downloadlibrb-39c4979dec4465d704aca3a1e4ad12c4bda578d4.tar.gz
librb-39c4979dec4465d704aca3a1e4ad12c4bda578d4.tar.bz2
librb-39c4979dec4465d704aca3a1e4ad12c4bda578d4.zip
fix: include sys/select.h only on systems that has one
-rw-r--r--configure.ac2
-rw-r--r--rb.c48
-rw-r--r--tests.c10
3 files changed, 48 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac
index 1c63a3e..e15a285 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,7 +43,7 @@ AC_ARG_ENABLE([posix-calls],
AS_IF([test "x$enable_posix_calls" = "xyes"],
[
AC_DEFINE([ENABLE_POSIX_CALLS], [1], [Enable posix helper functions])
- AC_CHECK_HEADERS(unistd.h)
+ AC_CHECK_HEADERS(unistd.h sys/select.h)
AC_CHECK_FUNCS([read write select],,
AC_MSG_ERROR(not found, needed by --enable-posix-calls))
],
diff --git a/rb.c b/rb.c
index ff5b9fb..07ecd9f 100644
--- a/rb.c
+++ b/rb.c
@@ -15,31 +15,41 @@
#if HAVE_CONFIG_H
+
# include "config.h"
+
#endif /* HAVE_CONFIG_H */
#ifdef TRACE_LOG
+
# define _GNU_SOURCE
# include <stdio.h>
# include <syscall.h>
# include <unistd.h>
-# define trace(x) do \
- { \
- printf("[%s:%d:%s():%ld]" , __FILE__, __LINE__, __func__, \
- syscall(SYS_gettid)); \
- printf x ; \
- printf("\n"); \
- } \
+# define trace(x) do \
+ { \
+ printf("[%s:%d:%s():%ld]" , __FILE__, __LINE__, __func__, \
+ syscall(SYS_gettid)); \
+ printf x ; \
+ printf("\n"); \
+ } \
while (0)
+
#else
+
# define trace(x)
+
#endif
#if HAVE_ASSERT_H
+
# include <assert.h>
+
#else /* HAVE_ASSERT_H */
+
# define assert(x)
+
#endif /* HAVE_ASSERT_H */
#include <errno.h>
@@ -48,17 +58,41 @@
#include <string.h>
#if ENABLE_THREADS
+
# include <fcntl.h>
# include <pthread.h>
# include <sys/socket.h>
# include <sys/time.h>
+
# if ENABLE_POSIX_CALLS
+
# include <signal.h>
+
# endif /* ENABLE_POSIX_CALLS */
+
#endif /* ENABLE_THREADS */
#if ENABLE_POSIX_CALLS
+
# include <unistd.h>
+
+# if HAVE_SYS_SELECT_H
+
+# include <sys/select.h>
+
+# else /* HAVE_SYS_SELECT_H */
+
+ /*
+ * some systems (like hpux 11.11) may not have sys/select.h as it is
+ * mandatory only from POSIX 1003.1-2001 and these are old includes
+ * for select() function
+ */
+
+# include <sys/time.h>
+# include <sys/types.h>
+
+# endif /* HAVE_SYS_SELECT_H */
+
#endif /* ENABLE_POSIX_CALLS */
#include "rb.h"
diff --git a/tests.c b/tests.c
index 94551cc..262a85e 100644
--- a/tests.c
+++ b/tests.c
@@ -20,12 +20,14 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
-#include <sys/select.h>
+#include <unistd.h>
+#include <sys/time.h>
-#include "mtest.h"
+#if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
-#include <sys/types.h>
-#include <unistd.h>
+#include "mtest.h"
#define TEST_BUFFER 0
#define TEST_FD_FILE 1