OSDN Git Service

am f8b41e81: Fix 32-bit bionic toybox build.
[android-x86/external-toybox.git] / lib / portability.h
index 143d10f..ff22fa5 100644 (file)
 
 #ifdef __GNUC__
 #define noreturn       __attribute__((noreturn))
+#if CFG_TOYBOX_DEBUG
+#define printf_format  __attribute__((format(printf, 1, 2)))
+#else
+#define printf_format
+#endif
 #else
 #define noreturn
+#define printf_format
 #endif
 
 // Always use long file support.
@@ -22,6 +28,9 @@
 
 #include <features.h>
 
+// Types various replacement prototypes need
+#include <sys/types.h>
+
 // Various constants old build environments might not have even if kernel does
 
 #ifndef AT_FDCWD
@@ -70,7 +79,7 @@ char *strptime(const char *buf, const char *format, struct tm *tm);
 // correct name to the broken name.
 
 char *dirname(char *path);
-char *__xpg_basename (char *path);
+char *__xpg_basename(char *path);
 static inline char *basename(char *path) { return __xpg_basename(path); }
 
 // uClibc pretends to be glibc and copied a lot of its bugs, but has a few more
@@ -145,15 +154,17 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag
 
 #endif // glibc in general
 
-#ifndef __GLIBC__
+#if !defined(__GLIBC__) && !defined(__BIONIC__)
 // POSIX basename.
 #include <libgen.h>
 #endif
 
-#ifdef __MUSL__
-#include <unistd.h>
-// Without this "rm -r dir" fails with "is directory".
-#define faccessat(A, B, C, D) faccessat(A, B, C, 0)
+// glibc was handled above; for 32-bit bionic we need to avoid a collision
+// with toybox's basename_r so we can't include <libgen.h> even though that
+// would give us a POSIX basename(3).
+#if defined(__BIONIC__)
+char *basename(char *path);
+char *dirname(char *path);
 #endif
 
 // Work out how to do endianness
@@ -222,10 +233,18 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream);
 #define O_NOFOLLOW 0
 #endif
 
+#ifndef O_NOATIME
+#define O_NOATIME 01000000
+#endif
+
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 02000000
 #endif
 
+#ifndef O_PATH
+#define O_PATH   010000000
+#endif
+
 #if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \
     && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__
 typedef double FLOAT;
@@ -238,11 +257,5 @@ pid_t xfork(void);
 #endif
 
 //#define strncpy(...) @@strncpyisbadmmkay@@
-//#define strncat(...) @@strcatisbadmmkay@@
+//#define strncat(...) @@strncatisbadmmkay@@
 
-#if CFG_TOYBOX_SELINUX
-#include <selinux/selinux.h>
-#else
-#define is_selinux_enabled() 0
-int getcon(void* con);
-#endif