annotate lib/portability.h @ 600:58d2fd7484bd

More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
author Rob Landley <rob@landley.net>
date Sat, 16 Jun 2012 14:19:56 -0500
parents b2194045c40e
children 8871e8002812
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
372
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
1 // The tendency of gcc to produce stupid warnings continues with
549
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
2 // warn_unused_result, which warns about things like ignoring the return code
372
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
3 // of nice(2) (which is completely useless since -1 is a legitimate return
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
4 // value on success and even the man page tells you to use errno instead).
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
5
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
6 // This makes it stop.
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
7
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
8 #undef _FORTIFY_SOURCE
9051cb744d0a Shut up even MORE gcc/glibc spurious warnings.
Rob Landley <rob@landley.net>
parents: 166
diff changeset
9
533
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 372
diff changeset
10 #define _FILE_OFFSET_BITS 64
31215cc6c9f2 Consolidate headers.
Rob Landley <rob@landley.net>
parents: 372
diff changeset
11
600
58d2fd7484bd More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
12 // This isn't in the spec, but it's how we determine what we're using.
550
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
13
600
58d2fd7484bd More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
14 #include <features.h>
550
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
15
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
16 #ifdef __GLIBC__
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
17 // An SUSv4 function that glibc refuses to #define without crazy #defines,
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
18 // see http://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
19 #include <time.h>
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
20 char *strptime(const char *buf, const char *format, struct tm *tm);
600
58d2fd7484bd More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
21 // Another one. "Function prototypes shall be provided." but aren't.
58d2fd7484bd More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
22 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
58d2fd7484bd More header fiddling: crypt.h is silly, SUSv4 requires crypt() to be prototyped in unistd.h. The fact glibc refuses to do so without a wacky #define is a glibc bug, treat it as such.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
23 char *crypt(const char *key, const char *salt);
550
b2194045c40e Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Rob Landley <rob@landley.net>
parents: 549
diff changeset
24 #endif
63
69efffcacd70 Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents: 53
diff changeset
25
166
5f1d3ad8a888 Add noreturn mark to [p]error_exit(), suggested by Charlie Shepherd.
Rob Landley <rob@landley.net>
parents: 100
diff changeset
26 #ifdef __GNUC__
5f1d3ad8a888 Add noreturn mark to [p]error_exit(), suggested by Charlie Shepherd.
Rob Landley <rob@landley.net>
parents: 100
diff changeset
27 #define noreturn __attribute__((noreturn))
5f1d3ad8a888 Add noreturn mark to [p]error_exit(), suggested by Charlie Shepherd.
Rob Landley <rob@landley.net>
parents: 100
diff changeset
28 #else
5f1d3ad8a888 Add noreturn mark to [p]error_exit(), suggested by Charlie Shepherd.
Rob Landley <rob@landley.net>
parents: 100
diff changeset
29 #define noreturn
5f1d3ad8a888 Add noreturn mark to [p]error_exit(), suggested by Charlie Shepherd.
Rob Landley <rob@landley.net>
parents: 100
diff changeset
30 #endif
100
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
31
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
32 #ifndef __APPLE__
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
33 #include <byteswap.h>
53
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 #include <endian.h>
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
35
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 #if __BYTE_ORDER == __BIG_ENDIAN
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 #define IS_BIG_ENDIAN 1
100
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
38 #else
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
39 #define IS_BIG_ENDIAN 0
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
40 #endif
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
41
549
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
42 int clearenv(void);
100
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
43 #else
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
44
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
45 #ifdef __BIG_ENDIAN__
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
46 #define IS_BIG_ENDIAN 1
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
47 #else
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
48 #define IS_BIG_ENDIAN 0
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
49 #endif
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
50
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
51 #endif
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
52
c3d1d74d5d8f MacOS X has a defective sed with no -r.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
53 #if IS_BIG_ENDIAN
53
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 #define IS_LITTLE_ENDIAN 0
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 #define SWAP_BE16(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 #define SWAP_BE32(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 #define SWAP_BE64(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 #define SWAP_LE16(x) bswap_16(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 #define SWAP_LE32(x) bswap_32(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 #define SWAP_LE64(x) bswap_64(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 #else
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 #define IS_LITTLE_ENDIAN 1
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 #define SWAP_BE16(x) bswap_16(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 #define SWAP_BE32(x) bswap_32(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 #define SWAP_BE64(x) bswap_64(x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
66 #define SWAP_LE16(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 #define SWAP_LE32(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 #define SWAP_LE64(x) (x)
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 #endif
94
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
70
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
71 // Some versions of gcc produce spurious "may be uninitialized" warnings in
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
72 // cases where it provably can't happen. Unfortunately, although this warning
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
73 // is calculated and produced separately from the "is definitely used
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
74 // uninitialized" warnings, there's no way to turn off the broken spurious "may
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
75 // be" warnings without also turning off the non-broken "is" warnings.
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
76
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
77 #if CFG_TOYBOX_DEBUG
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
78 #define GCC_BUG =0
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
79 #else
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
80 #define GCC_BUG
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 63
diff changeset
81 #endif
549
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
82
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
83 #if defined(__APPLE__) || defined(__ANDROID__)
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
84 ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
85 ssize_t getline(char **lineptr, size_t *n, FILE *stream);
1f5bd8c93093 Implement Apple and Android versions of getline(), getdelim(), and clearenv().
Georgi Chorbadzhiyski <gf@unixsol.org>
parents: 533
diff changeset
86 #endif