# HG changeset patch # User Rob Landley # Date 1359986852 21600 # Node ID 4ffb735aea5945552a74ebc3b67627827dac02cf # Parent 6b8cc11d517cad2d76de8d97699c505ac0d368c3 More support for old (~2008) build environments, move the #ifdef checks for symbols out of specific library version checks (shouldn't hurt anything), remove obsolete debug macro. diff -r 6b8cc11d517c -r 4ffb735aea59 lib/portability.h --- a/lib/portability.h Sun Feb 03 17:04:36 2013 -0600 +++ b/lib/portability.h Mon Feb 04 08:07:32 2013 -0600 @@ -19,10 +19,28 @@ #include +// Various constants old build environments might not have even if kernel does + #ifndef O_DIRECTORY #define O_DIRECTORY 0200000 #endif +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0400000 +#endif + +#ifndef AT_FDCWD +#define AT_FDCWD -100 +#endif + +#ifndef AT_SYMLINK_NOFOLLOW +#define AT_SYMLINK_NOFOLLOW 0x100 +#endif + +#ifndef AT_REMOVEDIR +#define AT_REMOVEDIR 0x200 +#endif + #if defined(__GLIBC__) // "Function prototypes shall be provided." but aren't. // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html @@ -38,15 +56,9 @@ #include #include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); -#ifndef O_NOFOLLOW -#define O_NOFOLLOW 00400000 /* don't follow links */ -#endif // When building under obsolete glibc, hold its hand a bit. -#elif __GLIBC_MINOR__ < 10 -#define AT_FDCWD -100 -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 +#elif __GLIBC__ == 2 && __GLIBC_MINOR__ < 10 #define fstatat fstatat64 int fstatat64(int dirfd, const char *pathname, void *buf, int flags); int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); @@ -63,10 +75,23 @@ int unlinkat(int dirfd, const char *pathname, int flags); #include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); + +// Straight from posix-2008, things old glibc didn't define + +int faccessat(int fd, const char *path, int amode, int flag); +int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag); +int mkdirat(int fd, const char *path, mode_t mode); +int symlinkat(const char *path1, int fd, const char *path2); +int mknodat(int fd, const char *path, mode_t mode, dev_t dev); +#include +int futimens(int fd, const struct timespec times[2]); +int utimensat(int fd, const char *path, const struct timespec times[2], int flag); #endif #endif +// Test for gcc + #ifdef __GNUC__ #define noreturn __attribute__((noreturn)) #else @@ -112,18 +137,6 @@ #define SWAP_LE64(x) (x) #endif -// Some versions of gcc produce spurious "may be uninitialized" warnings in -// cases where it provably can't happen. Unfortunately, although this warning -// is calculated and produced separately from the "is definitely used -// uninitialized" warnings, there's no way to turn off the broken spurious "may -// be" warnings without also turning off the non-broken "is" warnings. - -#if CFG_TOYBOX_DEBUG -#define GCC_BUG =0 -#else -#define GCC_BUG -#endif - #if defined(__APPLE__) || defined(__ANDROID__) ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); ssize_t getline(char **lineptr, size_t *n, FILE *stream);