summaryrefslogtreecommitdiff
path: root/lib/system.h
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2016-10-13 09:16:48 +0900
committerMark Wielaard <mjw@redhat.com>2016-10-13 11:24:03 +0200
commita24d52ac205b4983c80657b5aa2a7d90d7032837 (patch)
tree1fc2966e22391592ba4a6d94da7c68d86f64e51e /lib/system.h
parent60b2bf1b08c621492410b24e469b2bdf58d167d5 (diff)
downloadelfutils-a24d52ac205b4983c80657b5aa2a7d90d7032837.tar.gz
Do not depend on some non-POSIX features.
Define/open code memrchr, rawmemchr, powerof2 and TEMP_FAILURE_RETRY if not available through system headers. Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'lib/system.h')
-rw-r--r--lib/system.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/system.h b/lib/system.h
index ec387c31..e1c1c698 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -29,7 +29,12 @@
#ifndef LIB_SYSTEM_H
#define LIB_SYSTEM_H 1
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <argp.h>
+#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/param.h>
@@ -59,6 +64,9 @@
#define MIN(m, n) ((m) < (n) ? (m) : (n))
#endif
+#if !HAVE_DECL_POWEROF2
+#define powerof2(x) (((x) & ((x) - 1)) == 0)
+#endif
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
@@ -67,6 +75,14 @@
#define gettext_noop(Str) Str
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expression) \
+ ({ ssize_t __res; \
+ do \
+ __res = expression; \
+ while (__res == -1 && errno == EINTR); \
+ __res; });
+#endif
static inline ssize_t __attribute__ ((unused))
pwrite_retry (int fd, const void *buf, size_t len, off_t off)