comparison lib/portability.h @ 800:4ffb735aea59

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.
author Rob Landley <rob@landley.net>
date Mon, 04 Feb 2013 08:07:32 -0600
parents 9a6b08e7fe94
children bbec26ccb40c
comparison
equal deleted inserted replaced
799:6b8cc11d517c 800:4ffb735aea59
17 17
18 // This isn't in the spec, but it's how we determine what we're using. 18 // This isn't in the spec, but it's how we determine what we're using.
19 19
20 #include <features.h> 20 #include <features.h>
21 21
22 // Various constants old build environments might not have even if kernel does
23
22 #ifndef O_DIRECTORY 24 #ifndef O_DIRECTORY
23 #define O_DIRECTORY 0200000 25 #define O_DIRECTORY 0200000
26 #endif
27
28 #ifndef O_NOFOLLOW
29 #define O_NOFOLLOW 0400000
30 #endif
31
32 #ifndef AT_FDCWD
33 #define AT_FDCWD -100
34 #endif
35
36 #ifndef AT_SYMLINK_NOFOLLOW
37 #define AT_SYMLINK_NOFOLLOW 0x100
38 #endif
39
40 #ifndef AT_REMOVEDIR
41 #define AT_REMOVEDIR 0x200
24 #endif 42 #endif
25 43
26 #if defined(__GLIBC__) 44 #if defined(__GLIBC__)
27 // "Function prototypes shall be provided." but aren't. 45 // "Function prototypes shall be provided." but aren't.
28 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html 46 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
36 // uClibc pretends to be glibc and copied a lot of its bugs, but has a few more 54 // uClibc pretends to be glibc and copied a lot of its bugs, but has a few more
37 #if defined(__UCLIBC__) 55 #if defined(__UCLIBC__)
38 #include <unistd.h> 56 #include <unistd.h>
39 #include <stdio.h> 57 #include <stdio.h>
40 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); 58 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
41 #ifndef O_NOFOLLOW
42 #define O_NOFOLLOW 00400000 /* don't follow links */
43 #endif
44 59
45 // When building under obsolete glibc, hold its hand a bit. 60 // When building under obsolete glibc, hold its hand a bit.
46 #elif __GLIBC_MINOR__ < 10 61 #elif __GLIBC__ == 2 && __GLIBC_MINOR__ < 10
47 #define AT_FDCWD -100
48 #define AT_SYMLINK_NOFOLLOW 0x100
49 #define AT_REMOVEDIR 0x200
50 #define fstatat fstatat64 62 #define fstatat fstatat64
51 int fstatat64(int dirfd, const char *pathname, void *buf, int flags); 63 int fstatat64(int dirfd, const char *pathname, void *buf, int flags);
52 int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); 64 int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
53 char *stpcpy(char *dest, const char *src); 65 char *stpcpy(char *dest, const char *src);
54 #include <sys/stat.h> 66 #include <sys/stat.h>
61 uid_t owner, gid_t group, int flags); 73 uid_t owner, gid_t group, int flags);
62 int isblank(int c); 74 int isblank(int c);
63 int unlinkat(int dirfd, const char *pathname, int flags); 75 int unlinkat(int dirfd, const char *pathname, int flags);
64 #include <stdio.h> 76 #include <stdio.h>
65 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); 77 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
78
79 // Straight from posix-2008, things old glibc didn't define
80
81 int faccessat(int fd, const char *path, int amode, int flag);
82 int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag);
83 int mkdirat(int fd, const char *path, mode_t mode);
84 int symlinkat(const char *path1, int fd, const char *path2);
85 int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
86 #include <sys/time.h>
87 int futimens(int fd, const struct timespec times[2]);
88 int utimensat(int fd, const char *path, const struct timespec times[2], int flag);
66 #endif 89 #endif
67 90
68 #endif 91 #endif
92
93 // Test for gcc
69 94
70 #ifdef __GNUC__ 95 #ifdef __GNUC__
71 #define noreturn __attribute__((noreturn)) 96 #define noreturn __attribute__((noreturn))
72 #else 97 #else
73 #define noreturn 98 #define noreturn
110 #define SWAP_LE16(x) (x) 135 #define SWAP_LE16(x) (x)
111 #define SWAP_LE32(x) (x) 136 #define SWAP_LE32(x) (x)
112 #define SWAP_LE64(x) (x) 137 #define SWAP_LE64(x) (x)
113 #endif 138 #endif
114 139
115 // Some versions of gcc produce spurious "may be uninitialized" warnings in
116 // cases where it provably can't happen. Unfortunately, although this warning
117 // is calculated and produced separately from the "is definitely used
118 // uninitialized" warnings, there's no way to turn off the broken spurious "may
119 // be" warnings without also turning off the non-broken "is" warnings.
120
121 #if CFG_TOYBOX_DEBUG
122 #define GCC_BUG =0
123 #else
124 #define GCC_BUG
125 #endif
126
127 #if defined(__APPLE__) || defined(__ANDROID__) 140 #if defined(__APPLE__) || defined(__ANDROID__)
128 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); 141 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
129 ssize_t getline(char **lineptr, size_t *n, FILE *stream); 142 ssize_t getline(char **lineptr, size_t *n, FILE *stream);
130 #endif 143 #endif