OSDN Git Service

Merge remote-tracking branch 'toybox/master' into HEAD
[android-x86/external-toybox.git] / lib / portability.h
index f23d4f6..e0dd914 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
@@ -28,6 +24,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
 #define AT_REMOVEDIR 0x200
 #endif
 
+#ifndef RLIMIT_RTTIME
+#define RLIMIT_RTTIME 15
+#endif
+
+#ifndef SEEK_DATA
+#define SEEK_DATA 3
+#endif
+
 // We don't define GNU_dammit because we're not part of the gnu project, and
 // don't want to get any FSF on us. Unfortunately glibc (gnu libc)
 // won't give us Linux syscall wrappers without claiming to be part of the
@@ -76,7 +83,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
@@ -113,6 +120,9 @@ pid_t getsid(pid_t pid);
 #ifndef MS_SHARED
 #define MS_SHARED     (1<<20)
 #endif
+#ifndef MS_RELATIME
+#define MS_RELATIME (1<<21)
+#endif
 
 // When building under obsolete glibc (Ubuntu 8.04-ish), hold its hand a bit.
 #elif __GLIBC__ == 2 && __GLIBC_MINOR__ < 10
@@ -151,7 +161,7 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag
 
 #endif // glibc in general
 
-#ifndef __GLIBC__
+#if !defined(__GLIBC__)
 // POSIX basename.
 #include <libgen.h>
 #endif
@@ -214,6 +224,12 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream);
 #endif
 #if CFG_TOYBOX_UTMPX
 #include <utmpx.h>
+#else
+struct utmpx {int ut_type;};
+#define USER_PROCESS 0
+static inline struct utmpx *getutxent(void) {return 0;}
+static inline void setutxent(void) {;}
+static inline void endutxent(void) {;}
 #endif
 
 // Some systems don't define O_NOFOLLOW, and it varies by architecture, so...
@@ -222,10 +238,28 @@ 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
+
+// Glibc won't give you linux-kernel constants unless you say "no, a BUD lite"
+// even though linux has nothing to do with the FSF and never has.
+#ifndef F_SETPIPE_SZ
+#define F_SETPIPE_SZ 1031
+#endif
+
+#ifndef F_GETPIPE_SZ
+#define F_GETPIPE_SZ 1032
+#endif
+
 #if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \
     && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__
 typedef double FLOAT;
@@ -238,15 +272,11 @@ pid_t xfork(void);
 #endif
 
 //#define strncpy(...) @@strncpyisbadmmkay@@
-//#define strncat(...) @@strcatisbadmmkay@@
+//#define strncat(...) @@strncatisbadmmkay@@
 
-#if CFG_TOYBOX_SELINUX
-#include <selinux/selinux.h>
+#ifdef __ANDROID__
+#include <cutils/sched_policy.h>
 #else
-#define is_selinux_enabled() 0
-int getcon(void* con);
-#endif
-
-#if CFG_TOYBOX_SMACK
-#include <sys/smack.h>
+static inline int get_sched_policy(int tid, void *policy) {return 0;}
+static inline char *get_sched_policy_name(int policy) {return "unknown";}
 #endif