From f419bcb9dcfb6af60fbf1d58d92caf4b3d62a4da Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 26 Aug 2012 21:09:26 -0400 Subject: [PATCH 01/16] dladdr support for dynamic linker (nonstandard extension) based on patches submitted by boris brezillon. this commit also fixes the issue whereby the main application and libc don't have the address ranges of their mappings stored, which was theoretically a problem for RTLD_NEXT support in dlsym; it didn't actually matter because libc never calls dlsym, and it seemed to be doing the right thing (by chance) for symbols in the main program as well. --- include/dlfcn.h | 10 ++++++ src/ldso/dladdr.c | 9 +++++ src/ldso/dynlink.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/ldso/dladdr.c diff --git a/include/dlfcn.h b/include/dlfcn.h index dea74c7d..e98c8ca6 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -18,6 +18,16 @@ char *dlerror(void); void *dlopen(const char *, int); void *dlsym(void *, const char *); +#ifdef _GNU_SOURCE +typedef struct { + const char *dli_fname; + void *dli_fbase; + const char *dli_sname; + void *dli_saddr; +} Dl_info; +int dladdr(void *, Dl_info *); +#endif + #ifdef __cplusplus } #endif diff --git a/src/ldso/dladdr.c b/src/ldso/dladdr.c new file mode 100644 index 00000000..265bb681 --- /dev/null +++ b/src/ldso/dladdr.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include + +int __dladdr(void *, Dl_info *); + +int dladdr(void *addr, Dl_info *info) +{ + return __dladdr(addr, info); +} diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index c733dc5d..b8c26ace 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include #include #include @@ -584,6 +585,22 @@ static size_t find_dyn(Phdr *ph, size_t cnt, size_t stride) return 0; } +static void find_map_range(Phdr *ph, size_t cnt, size_t stride, struct dso *p) +{ + size_t min_addr = -1, max_addr = 0; + for (; cnt--; ph = (void *)((char *)ph + stride)) { + if (ph->p_type != PT_LOAD) continue; + if (ph->p_vaddr < min_addr) + min_addr = ph->p_vaddr; + if (ph->p_vaddr+ph->p_memsz > max_addr) + max_addr = ph->p_vaddr+ph->p_memsz; + } + min_addr &= -PAGE_SIZE; + max_addr = (max_addr + PAGE_SIZE-1) & -PAGE_SIZE; + p->map = p->base + min_addr; + p->map_len = max_addr - min_addr; +} + static void do_init_fini(struct dso *p) { size_t dyn[DYN_CNT] = {0}; @@ -647,6 +664,8 @@ void *__dynlink(int argc, char **argv) lib->name = lib->shortname = "libc.so"; lib->global = 1; ehdr = (void *)lib->base; + find_map_range((void *)(aux[AT_BASE]+ehdr->e_phoff), + ehdr->e_phnum, ehdr->e_phentsize, lib); lib->dynv = (void *)(lib->base + find_dyn( (void *)(aux[AT_BASE]+ehdr->e_phoff), ehdr->e_phnum, ehdr->e_phentsize)); @@ -666,6 +685,8 @@ void *__dynlink(int argc, char **argv) app->name = argv[0]; app->dynv = (void *)(app->base + find_dyn( (void *)aux[AT_PHDR], aux[AT_PHNUM], aux[AT_PHENT])); + find_map_range((void *)aux[AT_PHDR], + aux[AT_PHNUM], aux[AT_PHENT], app); } else { int fd; char *ldname = argv[0]; @@ -891,6 +912,67 @@ failed: return 0; } +int __dladdr(void *addr, Dl_info *info) +{ + struct dso *p; + Sym *sym; + uint32_t nsym; + char *strings; + size_t i; + void *best = 0; + char *bestname; + + pthread_rwlock_rdlock(&lock); + for (p=head; p && (unsigned char *)addr-p->map>p->map_len; p=p->next); + pthread_rwlock_unlock(&lock); + + if (!p) return 0; + + sym = p->syms; + strings = p->strings; + if (p->hashtab) { + nsym = p->hashtab[1]; + } else { + uint32_t *buckets; + uint32_t *hashval; + buckets = p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4); + sym += p->ghashtab[1]; + for (i = 0; i < p->ghashtab[0]; i++) { + if (buckets[i] > nsym) + nsym = buckets[i]; + } + if (nsym) { + nsym -= p->ghashtab[1]; + hashval = buckets + p->ghashtab[0] + nsym; + do nsym++; + while (!(*hashval++ & 1)); + } + } + + for (; nsym; nsym--, sym++) { + if (sym->st_shndx && sym->st_value + && (1<<(sym->st_info&0xf) & OK_TYPES) + && (1<<(sym->st_info>>4) & OK_BINDS)) { + void *symaddr = p->base + sym->st_value; + if (symaddr > addr || symaddr < best) + continue; + best = symaddr; + bestname = strings + sym->st_name; + if (addr == symaddr) + break; + } + } + + if (!best) return 0; + + info->dli_fname = p->name; + info->dli_fbase = p->base; + info->dli_sname = bestname; + info->dli_saddr = best; + + return 1; +} + void *__dlsym(void *p, const char *s, void *ra) { void *res; @@ -908,6 +990,10 @@ void *__dlsym(void *p, const char *s, void *ra) { return 0; } +int __dladdr (void *addr, Dl_info *info) +{ + return 0; +} #endif char *dlerror() -- 2.20.1 From 8b28aa9c94e7c6179d70fe73afcd3fff29809d61 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 27 Aug 2012 10:07:32 -0400 Subject: [PATCH 02/16] fix bug caused by main app & libc having map set; cannot free them --- src/ldso/dynlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index b8c26ace..93a4b44c 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -572,7 +572,7 @@ static void free_all(struct dso *p) struct dso *n; while (p) { n = p->next; - if (p->map) free(p); + if (p->map && p!=libc && p!=head) free(p); p = n; } } -- 2.20.1 From b439c051c7eee4eb4b93fc382f993aa6305ce530 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 29 Aug 2012 09:36:02 -0400 Subject: [PATCH 03/16] get rid of eh_frame bloat if needed for debugging, it will be output in the .debug_frame section instead, where it is not part of the loaded program and where the strip command is free to strip it. --- configure | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 11051800..4e3931c1 100755 --- a/configure +++ b/configure @@ -226,15 +226,24 @@ test "x$debug" = xyes && CFLAGS_AUTO="-g" tryflag CFLAGS_AUTO -pipe # -# If debugging is disabled, omit bloated DWARF2 unwind tables & frame ptr +# If debugging is disabled, omit frame pointer. Modern GCC does this +# anyway on most archs even when debugging is enabled since the frame +# pointer is no longer needed for debugging. # if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then : else -tryflag CFLAGS_AUTO -fno-unwind-tables -tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables tryflag CFLAGS_AUTO -fomit-frame-pointer fi +# +# Modern GCC wants to put DWARF tables (used for debugging and +# unwinding) in the loaded part of the program where they are +# unstrippable. These options force them back to debug sections (and +# cause them not to get generated at all if debugging is off). +# +tryflag CFLAGS_AUTO -fno-unwind-tables +tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables + # # Some optimization levels add bloated alignment that hurt performance # -- 2.20.1 From 88bf5a8a8d7d796f63cca8589f4de67aa8345f1a Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 29 Aug 2012 12:41:29 -0400 Subject: [PATCH 04/16] add sha256/sha512 crypt based on versions sent to the list by nsz, with some simplification and debloating. i'd still like to get them a bit smaller, or ideally merge them into a single file with most of the code being shared, but that can be done later. --- src/misc/crypt.c | 2 +- src/misc/crypt_r.c | 6 + src/misc/crypt_sha256.c | 322 ++++++++++++++++++++++++++++++++++ src/misc/crypt_sha512.c | 371 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 700 insertions(+), 1 deletion(-) create mode 100644 src/misc/crypt_sha256.c create mode 100644 src/misc/crypt_sha512.c diff --git a/src/misc/crypt.c b/src/misc/crypt.c index fc5c4ee1..f1e310f6 100644 --- a/src/misc/crypt.c +++ b/src/misc/crypt.c @@ -6,6 +6,6 @@ char *__crypt_r(const char *, const char *, struct crypt_data *); char *crypt(const char *key, const char *salt) { /* Note: update this size when we add more hash types */ - static char buf[64]; + static char buf[128]; return __crypt_r(key, salt, (struct crypt_data *)buf); } diff --git a/src/misc/crypt_r.c b/src/misc/crypt_r.c index f4716d6f..1c7f9cf0 100644 --- a/src/misc/crypt_r.c +++ b/src/misc/crypt_r.c @@ -6,6 +6,8 @@ struct crypt_data; char *__crypt_des(const char *, const char *, char *); char *__crypt_md5(const char *, const char *, char *); char *__crypt_blowfish(const char *, const char *, char *); +char *__crypt_sha256(const char *, const char *, char *); +char *__crypt_sha512(const char *, const char *, char *); char *__crypt_r(const char *key, const char *salt, struct crypt_data *data) { @@ -17,6 +19,10 @@ char *__crypt_r(const char *key, const char *salt, struct crypt_data *data) #endif if (salt[1] == '2' && salt[3] == '$') return __crypt_blowfish(key, salt, output); + if (salt[1] == '5' && salt[2] == '$') + return __crypt_sha256(key, salt, output); + if (salt[1] == '6' && salt[2] == '$') + return __crypt_sha512(key, salt, output); } return __crypt_des(key, salt, output); } diff --git a/src/misc/crypt_sha256.c b/src/misc/crypt_sha256.c new file mode 100644 index 00000000..95e79b6e --- /dev/null +++ b/src/misc/crypt_sha256.c @@ -0,0 +1,322 @@ +/* + * public domain sha256 crypt implementation + * + * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt + * in this implementation at least 32bit int is assumed, + * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is rejected + * in the salt and rounds= setting must contain a valid iteration count, + * on error "*" is returned. + */ +#include +#include +#include +#include +#include + +/* public domain sha256 implementation based on fips180-3 */ + +struct sha256 { + uint64_t len; /* processed message length */ + uint32_t h[8]; /* hash state */ + uint8_t buf[64]; /* message block buffer */ +}; + +static uint32_t ror(uint32_t n, int k) { return (n >> k) | (n << (32-k)); } +#define Ch(x,y,z) (z ^ (x & (y ^ z))) +#define Maj(x,y,z) ((x & y) | (z & (x | y))) +#define S0(x) (ror(x,2) ^ ror(x,13) ^ ror(x,22)) +#define S1(x) (ror(x,6) ^ ror(x,11) ^ ror(x,25)) +#define R0(x) (ror(x,7) ^ ror(x,18) ^ (x>>3)) +#define R1(x) (ror(x,17) ^ ror(x,19) ^ (x>>10)) + +static const uint32_t K[64] = { +0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, +0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, +0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, +0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, +0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, +0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, +0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, +0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +}; + +static void processblock(struct sha256 *s, const uint8_t *buf) +{ + uint32_t W[64], t1, t2, a, b, c, d, e, f, g, h; + int i; + + for (i = 0; i < 16; i++) { + W[i] = (uint32_t)buf[4*i]<<24; + W[i] |= (uint32_t)buf[4*i+1]<<16; + W[i] |= (uint32_t)buf[4*i+2]<<8; + W[i] |= buf[4*i+3]; + } + for (; i < 64; i++) + W[i] = R1(W[i-2]) + W[i-7] + R0(W[i-15]) + W[i-16]; + a = s->h[0]; + b = s->h[1]; + c = s->h[2]; + d = s->h[3]; + e = s->h[4]; + f = s->h[5]; + g = s->h[6]; + h = s->h[7]; + for (i = 0; i < 64; i++) { + t1 = h + S1(e) + Ch(e,f,g) + K[i] + W[i]; + t2 = S0(a) + Maj(a,b,c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + s->h[0] += a; + s->h[1] += b; + s->h[2] += c; + s->h[3] += d; + s->h[4] += e; + s->h[5] += f; + s->h[6] += g; + s->h[7] += h; +} + +static void pad(struct sha256 *s) +{ + unsigned r = s->len % 64; + + s->buf[r++] = 0x80; + if (r > 56) { + memset(s->buf + r, 0, 64 - r); + r = 0; + processblock(s, s->buf); + } + memset(s->buf + r, 0, 56 - r); + s->len *= 8; + s->buf[56] = s->len >> 56; + s->buf[57] = s->len >> 48; + s->buf[58] = s->len >> 40; + s->buf[59] = s->len >> 32; + s->buf[60] = s->len >> 24; + s->buf[61] = s->len >> 16; + s->buf[62] = s->len >> 8; + s->buf[63] = s->len; + processblock(s, s->buf); +} + +void sha256_init(struct sha256 *s) +{ + s->len = 0; + s->h[0] = 0x6a09e667; + s->h[1] = 0xbb67ae85; + s->h[2] = 0x3c6ef372; + s->h[3] = 0xa54ff53a; + s->h[4] = 0x510e527f; + s->h[5] = 0x9b05688c; + s->h[6] = 0x1f83d9ab; + s->h[7] = 0x5be0cd19; +} + +void sha256_sum(struct sha256 *s, uint8_t md[20]) +{ + int i; + + pad(s); + for (i = 0; i < 8; i++) { + md[4*i] = s->h[i] >> 24; + md[4*i+1] = s->h[i] >> 16; + md[4*i+2] = s->h[i] >> 8; + md[4*i+3] = s->h[i]; + } +} + +void sha256_update(struct sha256 *s, const void *m, unsigned long len) +{ + const uint8_t *p = m; + unsigned r = s->len % 64; + + s->len += len; + if (r) { + if (len < 64 - r) { + memcpy(s->buf + r, p, len); + return; + } + memcpy(s->buf + r, p, 64 - r); + len -= 64 - r; + p += 64 - r; + processblock(s, s->buf); + } + for (; len >= 64; len -= 64, p += 64) + processblock(s, p); + memcpy(s->buf, p, len); +} + +static unsigned char b64[] = +"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +static char *to64(char *s, unsigned int u, int n) +{ + while (--n >= 0) { + *s++ = b64[u % 64]; + u /= 64; + } + return s; +} + +/* key limit is not part of the original design, added for DoS protection. + * rounds limit has been lowered (versus the reference/spec), also for DoS + * protection. runtime is O(klen^2 + klen*rounds) */ +#define KEY_MAX 256 +#define SALT_MAX 16 +#define ROUNDS_DEFAULT 5000 +#define ROUNDS_MIN 1000 +#define ROUNDS_MAX 50000 + +/* hash n bytes of the repeated md message digest */ +static void hashmd(struct sha256 *s, unsigned int n, const void *md) +{ + unsigned int i; + + for (i = n; i > 32; i -= 32) + sha256_update(s, md, 32); + sha256_update(s, md, i); +} + +static char *sha256crypt(const char *key, const char *setting, char *output) +{ + struct sha256 ctx; + unsigned char md[32], kmd[32], smd[32]; + unsigned int i, r, klen, slen; + char rounds[20] = ""; + const char *salt; + char *p; + + /* reject large keys */ + klen = strnlen(key, KEY_MAX+1); + if (klen > KEY_MAX) + return 0; + + /* setting: $5$rounds=n$salt$ (rounds=n$ and closing $ are optional) */ + if (strncmp(setting, "$5$", 3) != 0) + return 0; + salt = setting + 3; + + r = ROUNDS_DEFAULT; + if (strncmp(salt, "rounds=", sizeof "rounds=" - 1) == 0) { + unsigned long u; + char *end; + + /* + * this is a deviation from the reference: + * bad rounds setting is rejected if it is + * - empty + * - unterminated (missing '$') + * - begins with anything but a decimal digit + * the reference implementation treats these bad + * rounds as part of the salt or parse them with + * strtoul semantics which may cause problems + * including non-portable hashes that depend on + * the host's value of ULONG_MAX. + */ + salt += sizeof "rounds=" - 1; + if (!isdigit(*salt)) + return 0; + u = strtoul(salt, &end, 10); + if (*end != '$') + return 0; + salt = end+1; + if (u < ROUNDS_MIN) + r = ROUNDS_MIN; + else if (u > ROUNDS_MAX) + r = ROUNDS_MAX; + else + r = u; + /* needed when rounds is zero prefixed or out of bounds */ + sprintf(rounds, "rounds=%u$", r); + } + + for (i = 0; i < SALT_MAX && salt[i] && salt[i] != '$'; i++) + /* reject characters that interfere with /etc/shadow parsing */ + if (salt[i] == '\n' || salt[i] == ':') + return 0; + slen = i; + + /* B = sha(key salt key) */ + sha256_init(&ctx); + sha256_update(&ctx, key, klen); + sha256_update(&ctx, salt, slen); + sha256_update(&ctx, key, klen); + sha256_sum(&ctx, md); + + /* A = sha(key salt repeat-B alternate-B-key) */ + sha256_init(&ctx); + sha256_update(&ctx, key, klen); + sha256_update(&ctx, salt, slen); + hashmd(&ctx, klen, md); + for (i = klen; i > 0; i >>= 1) + if (i & 1) + sha256_update(&ctx, md, sizeof md); + else + sha256_update(&ctx, key, klen); + sha256_sum(&ctx, md); + + /* DP = sha(repeat-key), this step takes O(klen^2) time */ + sha256_init(&ctx); + for (i = 0; i < klen; i++) + sha256_update(&ctx, key, klen); + sha256_sum(&ctx, kmd); + + /* DS = sha(repeat-salt) */ + sha256_init(&ctx); + for (i = 0; i < 16 + md[0]; i++) + sha256_update(&ctx, salt, slen); + sha256_sum(&ctx, smd); + + /* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */ + for (i = 0; i < r; i++) { + sha256_init(&ctx); + if (i % 2) + hashmd(&ctx, klen, kmd); + else + sha256_update(&ctx, md, sizeof md); + if (i % 3) + sha256_update(&ctx, smd, slen); + if (i % 7) + hashmd(&ctx, klen, kmd); + if (i % 2) + sha256_update(&ctx, md, sizeof md); + else + hashmd(&ctx, klen, kmd); + sha256_sum(&ctx, md); + } + + /* output is $5$rounds=n$salt$hash */ + p = output; + p += sprintf(p, "$5$%s%.*s$", rounds, slen, salt); + static const unsigned char perm[][3] = { + 0,10,20,21,1,11,12,22,2,3,13,23,24,4,14, + 15,25,5,6,16,26,27,7,17,18,28,8,9,19,29 }; + for (i=0; i<10; i++) p = to64(p, + (md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4); + p = to64(p, (md[31]<<8)|md[30], 3); + *p = 0; + return output; +} + +char *__crypt_sha256(const char *key, const char *setting, char *output) +{ + static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; + static const char testsetting[] = "$5$rounds=1234$abc0123456789$"; + static const char testhash[] = "$5$rounds=1234$abc0123456789$3VfDjPt05VHFn47C/ojFZ6KRPYrOjj1lLbH.dkF3bZ6"; + char testbuf[128]; + char *p, *q; + + p = sha256crypt(key, setting, output); + /* self test and stack cleanup */ + q = sha256crypt(testkey, testsetting, testbuf); + if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) + return "*"; + return p; +} diff --git a/src/misc/crypt_sha512.c b/src/misc/crypt_sha512.c new file mode 100644 index 00000000..7ca804e8 --- /dev/null +++ b/src/misc/crypt_sha512.c @@ -0,0 +1,371 @@ +/* + * public domain sha512 crypt implementation + * + * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt + * in this implementation at least 32bit int is assumed, + * key length is limited, the $6$ prefix is mandatory, '\n' and ':' is rejected + * in the salt and rounds= setting must contain a valid iteration count, + * on error "*" is returned. + */ +#include +#include +#include +#include +#include + +/* public domain sha512 implementation based on fips180-3 */ +/* >=2^64 bits messages are not supported (about 2000 peta bytes) */ + +struct sha512 { + uint64_t len; /* processed message length */ + uint64_t h[8]; /* hash state */ + uint8_t buf[128]; /* message block buffer */ +}; + +static uint64_t ror(uint64_t n, int k) { return (n >> k) | (n << (64-k)); } +#define Ch(x,y,z) (z ^ (x & (y ^ z))) +#define Maj(x,y,z) ((x & y) | (z & (x | y))) +#define S0(x) (ror(x,28) ^ ror(x,34) ^ ror(x,39)) +#define S1(x) (ror(x,14) ^ ror(x,18) ^ ror(x,41)) +#define R0(x) (ror(x,1) ^ ror(x,8) ^ (x>>7)) +#define R1(x) (ror(x,19) ^ ror(x,61) ^ (x>>6)) + +static const uint64_t K[80] = { +0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, +0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, +0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, +0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, +0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, +0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, +0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, +0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, +0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, +0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, +0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, +0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, +0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, +0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, +0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, +0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, +0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, +0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, +0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, +0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL +}; + +static void processblock(struct sha512 *s, const uint8_t *buf) +{ + uint64_t W[80], t1, t2, a, b, c, d, e, f, g, h; + int i; + + for (i = 0; i < 16; i++) { + W[i] = (uint64_t)buf[8*i]<<56; + W[i] |= (uint64_t)buf[8*i+1]<<48; + W[i] |= (uint64_t)buf[8*i+2]<<40; + W[i] |= (uint64_t)buf[8*i+3]<<32; + W[i] |= (uint64_t)buf[8*i+4]<<24; + W[i] |= (uint64_t)buf[8*i+5]<<16; + W[i] |= (uint64_t)buf[8*i+6]<<8; + W[i] |= buf[8*i+7]; + } + for (; i < 80; i++) + W[i] = R1(W[i-2]) + W[i-7] + R0(W[i-15]) + W[i-16]; + a = s->h[0]; + b = s->h[1]; + c = s->h[2]; + d = s->h[3]; + e = s->h[4]; + f = s->h[5]; + g = s->h[6]; + h = s->h[7]; + for (i = 0; i < 80; i++) { + t1 = h + S1(e) + Ch(e,f,g) + K[i] + W[i]; + t2 = S0(a) + Maj(a,b,c); + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + s->h[0] += a; + s->h[1] += b; + s->h[2] += c; + s->h[3] += d; + s->h[4] += e; + s->h[5] += f; + s->h[6] += g; + s->h[7] += h; +} + +static void pad(struct sha512 *s) +{ + unsigned r = s->len % 128; + + s->buf[r++] = 0x80; + if (r > 112) { + memset(s->buf + r, 0, 128 - r); + r = 0; + processblock(s, s->buf); + } + memset(s->buf + r, 0, 120 - r); + s->len *= 8; + s->buf[120] = s->len >> 56; + s->buf[121] = s->len >> 48; + s->buf[122] = s->len >> 40; + s->buf[123] = s->len >> 32; + s->buf[124] = s->len >> 24; + s->buf[125] = s->len >> 16; + s->buf[126] = s->len >> 8; + s->buf[127] = s->len; + processblock(s, s->buf); +} + +static void sha512_init(struct sha512 *s) +{ + s->len = 0; + s->h[0] = 0x6a09e667f3bcc908ULL; + s->h[1] = 0xbb67ae8584caa73bULL; + s->h[2] = 0x3c6ef372fe94f82bULL; + s->h[3] = 0xa54ff53a5f1d36f1ULL; + s->h[4] = 0x510e527fade682d1ULL; + s->h[5] = 0x9b05688c2b3e6c1fULL; + s->h[6] = 0x1f83d9abfb41bd6bULL; + s->h[7] = 0x5be0cd19137e2179ULL; +} + +static void sha512_sum(struct sha512 *s, uint8_t md[20]) +{ + int i; + + pad(s); + for (i = 0; i < 8; i++) { + md[8*i] = s->h[i] >> 56; + md[8*i+1] = s->h[i] >> 48; + md[8*i+2] = s->h[i] >> 40; + md[8*i+3] = s->h[i] >> 32; + md[8*i+4] = s->h[i] >> 24; + md[8*i+5] = s->h[i] >> 16; + md[8*i+6] = s->h[i] >> 8; + md[8*i+7] = s->h[i]; + } +} + +static void sha512_update(struct sha512 *s, const void *m, unsigned long len) +{ + const uint8_t *p = m; + unsigned r = s->len % 128; + + s->len += len; + if (r) { + if (len < 128 - r) { + memcpy(s->buf + r, p, len); + return; + } + memcpy(s->buf + r, p, 128 - r); + len -= 128 - r; + p += 128 - r; + processblock(s, s->buf); + } + for (; len >= 128; len -= 128, p += 128) + processblock(s, p); + memcpy(s->buf, p, len); +} + +static unsigned char b64[] = +"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +static char *to64(char *s, unsigned int u, int n) +{ + while (--n >= 0) { + *s++ = b64[u % 64]; + u /= 64; + } + return s; +} + +/* key limit is not part of the original design, added for DoS protection. + * rounds limit has been lowered (versus the reference/spec), also for DoS + * protection. runtime is O(klen^2 + klen*rounds) */ +#define KEY_MAX 256 +#define SALT_MAX 16 +#define ROUNDS_DEFAULT 5000 +#define ROUNDS_MIN 1000 +#define ROUNDS_MAX 50000 + +/* hash n bytes of the repeated md message digest */ +static void hashmd(struct sha512 *s, unsigned int n, const void *md) +{ + unsigned int i; + + for (i = n; i > 64; i -= 64) + sha512_update(s, md, 64); + sha512_update(s, md, i); +} + +static char *sha512crypt(const char *key, const char *setting, char *output) +{ + struct sha512 ctx; + unsigned char md[64], kmd[64], smd[64]; + unsigned int i, r, klen, slen; + char rounds[20] = ""; + const char *salt; + char *p; + + /* reject large keys */ + for (i = 0; i <= KEY_MAX && key[i]; i++); + if (i > KEY_MAX) + return 0; + klen = i; + + /* setting: $6$rounds=n$salt$ (rounds=n$ and closing $ are optional) */ + if (strncmp(setting, "$6$", 3) != 0) + return 0; + salt = setting + 3; + + r = ROUNDS_DEFAULT; + if (strncmp(salt, "rounds=", sizeof "rounds=" - 1) == 0) { + unsigned long u; + char *end; + + /* + * this is a deviation from the reference: + * bad rounds setting is rejected if it is + * - empty + * - unterminated (missing '$') + * - begins with anything but a decimal digit + * the reference implementation treats these bad + * rounds as part of the salt or parse them with + * strtoul semantics which may cause problems + * including non-portable hashes that depend on + * the host's value of ULONG_MAX. + */ + salt += sizeof "rounds=" - 1; + if (!isdigit(*salt)) + return 0; + u = strtoul(salt, &end, 10); + if (*end != '$') + return 0; + salt = end+1; + if (u < ROUNDS_MIN) + r = ROUNDS_MIN; + else if (u > ROUNDS_MAX) + r = ROUNDS_MAX; + else + r = u; + /* needed when rounds is zero prefixed or out of bounds */ + sprintf(rounds, "rounds=%u$", r); + } + + for (i = 0; i < SALT_MAX && salt[i] && salt[i] != '$'; i++) + /* reject characters that interfere with /etc/shadow parsing */ + if (salt[i] == '\n' || salt[i] == ':') + return 0; + slen = i; + + /* B = sha(key salt key) */ + sha512_init(&ctx); + sha512_update(&ctx, key, klen); + sha512_update(&ctx, salt, slen); + sha512_update(&ctx, key, klen); + sha512_sum(&ctx, md); + + /* A = sha(key salt repeat-B alternate-B-key) */ + sha512_init(&ctx); + sha512_update(&ctx, key, klen); + sha512_update(&ctx, salt, slen); + hashmd(&ctx, klen, md); + for (i = klen; i > 0; i >>= 1) + if (i & 1) + sha512_update(&ctx, md, sizeof md); + else + sha512_update(&ctx, key, klen); + sha512_sum(&ctx, md); + + /* DP = sha(repeat-key), this step takes O(klen^2) time */ + sha512_init(&ctx); + for (i = 0; i < klen; i++) + sha512_update(&ctx, key, klen); + sha512_sum(&ctx, kmd); + + /* DS = sha(repeat-salt) */ + sha512_init(&ctx); + for (i = 0; i < 16 + md[0]; i++) + sha512_update(&ctx, salt, slen); + sha512_sum(&ctx, smd); + + /* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */ + for (i = 0; i < r; i++) { + sha512_init(&ctx); + if (i % 2) + hashmd(&ctx, klen, kmd); + else + sha512_update(&ctx, md, sizeof md); + if (i % 3) + sha512_update(&ctx, smd, slen); + if (i % 7) + hashmd(&ctx, klen, kmd); + if (i % 2) + sha512_update(&ctx, md, sizeof md); + else + hashmd(&ctx, klen, kmd); + sha512_sum(&ctx, md); + } + + /* output is $6$rounds=n$salt$hash */ + p = output; + p += sprintf(p, "$6$%s%.*s$", rounds, slen, salt); +#if 1 + static const unsigned char perm[][3] = { + 0,21,42,22,43,1,44,2,23,3,24,45,25,46,4, + 47,5,26,6,27,48,28,49,7,50,8,29,9,30,51, + 31,52,10,53,11,32,12,33,54,34,55,13,56,14,35, + 15,36,57,37,58,16,59,17,38,18,39,60,40,61,19, + 62,20,41 }; + for (i=0; i<21; i++) p = to64(p, + (md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4); +#else + p = to64(p, (md[0]<<16)|(md[21]<<8)|md[42], 4); + p = to64(p, (md[22]<<16)|(md[43]<<8)|md[1], 4); + p = to64(p, (md[44]<<16)|(md[2]<<8)|md[23], 4); + p = to64(p, (md[3]<<16)|(md[24]<<8)|md[45], 4); + p = to64(p, (md[25]<<16)|(md[46]<<8)|md[4], 4); + p = to64(p, (md[47]<<16)|(md[5]<<8)|md[26], 4); + p = to64(p, (md[6]<<16)|(md[27]<<8)|md[48], 4); + p = to64(p, (md[28]<<16)|(md[49]<<8)|md[7], 4); + p = to64(p, (md[50]<<16)|(md[8]<<8)|md[29], 4); + p = to64(p, (md[9]<<16)|(md[30]<<8)|md[51], 4); + p = to64(p, (md[31]<<16)|(md[52]<<8)|md[10], 4); + p = to64(p, (md[53]<<16)|(md[11]<<8)|md[32], 4); + p = to64(p, (md[12]<<16)|(md[33]<<8)|md[54], 4); + p = to64(p, (md[34]<<16)|(md[55]<<8)|md[13], 4); + p = to64(p, (md[56]<<16)|(md[14]<<8)|md[35], 4); + p = to64(p, (md[15]<<16)|(md[36]<<8)|md[57], 4); + p = to64(p, (md[37]<<16)|(md[58]<<8)|md[16], 4); + p = to64(p, (md[59]<<16)|(md[17]<<8)|md[38], 4); + p = to64(p, (md[18]<<16)|(md[39]<<8)|md[60], 4); + p = to64(p, (md[40]<<16)|(md[61]<<8)|md[19], 4); + p = to64(p, (md[62]<<16)|(md[20]<<8)|md[41], 4); +#endif + p = to64(p, md[63], 2); + *p = 0; + return output; +} + +char *__crypt_sha512(const char *key, const char *setting, char *output) +{ + static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; + static const char testsetting[] = "$6$rounds=1234$abc0123456789$"; + static const char testhash[] = "$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1"; + char testbuf[128]; + char *p, *q; + + p = sha512crypt(key, setting, output); + /* self test and stack cleanup */ + q = sha512crypt(testkey, testsetting, testbuf); + if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) + return "*"; + return p; +} -- 2.20.1 From 507b6091fa75903ff05c21a4470b7b7cc3061d0d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 29 Aug 2012 12:44:27 -0400 Subject: [PATCH 05/16] limit sha512 rounds to similar runtime to sha256 limit these limits could definitely use review, but for now, i feel consistency and erring on the side of preventing servers from getting bogged down by excessively-slow user-provided settings (think .htpasswd) are the best policy. blowfish should be updated to match. --- src/misc/crypt_sha512.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc/crypt_sha512.c b/src/misc/crypt_sha512.c index 7ca804e8..2c0de698 100644 --- a/src/misc/crypt_sha512.c +++ b/src/misc/crypt_sha512.c @@ -193,7 +193,7 @@ static char *to64(char *s, unsigned int u, int n) #define SALT_MAX 16 #define ROUNDS_DEFAULT 5000 #define ROUNDS_MIN 1000 -#define ROUNDS_MAX 50000 +#define ROUNDS_MAX 20000 /* hash n bytes of the repeated md message digest */ static void hashmd(struct sha512 *s, unsigned int n, const void *md) -- 2.20.1 From 13157b025e7e19f7ecc27ee93e69057b7fda9b37 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 29 Aug 2012 12:56:12 -0400 Subject: [PATCH 06/16] anti-DoS rounds count limits for blowfish and des crypt all of the limits could use review, but err on the side of avoiding excessive rounds for now. --- src/misc/crypt_blowfish.c | 2 +- src/misc/crypt_des.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc/crypt_blowfish.c b/src/misc/crypt_blowfish.c index d3f79851..bd37be84 100644 --- a/src/misc/crypt_blowfish.c +++ b/src/misc/crypt_blowfish.c @@ -625,7 +625,7 @@ static char *BF_crypt(const char *key, const char *setting, } count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0')); - if (count < min || BF_decode(data.binary.salt, &setting[7], 16)) { + if (count < min || count > 2048 || BF_decode(data.binary.salt, &setting[7], 16)) { return NULL; } BF_swap(data.binary.salt, 4); diff --git a/src/misc/crypt_des.c b/src/misc/crypt_des.c index 4454a130..d7b2b15a 100644 --- a/src/misc/crypt_des.c +++ b/src/misc/crypt_des.c @@ -911,7 +911,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char return NULL; count |= value << (i - 1) * 6; } - if (!count) + if (!count || count > 262143) return NULL; for (i = 5, salt = 0; i < 9; i++) { -- 2.20.1 From 0447b8dc5c4479fa7b505d2b9d341bca12adbd25 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 30 Aug 2012 08:27:08 -0400 Subject: [PATCH 07/16] fix missing statics in crypt_sha256 code --- src/misc/crypt_sha256.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/misc/crypt_sha256.c b/src/misc/crypt_sha256.c index 95e79b6e..2dc27ee7 100644 --- a/src/misc/crypt_sha256.c +++ b/src/misc/crypt_sha256.c @@ -106,7 +106,7 @@ static void pad(struct sha256 *s) processblock(s, s->buf); } -void sha256_init(struct sha256 *s) +static void sha256_init(struct sha256 *s) { s->len = 0; s->h[0] = 0x6a09e667; @@ -119,7 +119,7 @@ void sha256_init(struct sha256 *s) s->h[7] = 0x5be0cd19; } -void sha256_sum(struct sha256 *s, uint8_t md[20]) +static void sha256_sum(struct sha256 *s, uint8_t md[20]) { int i; @@ -132,7 +132,7 @@ void sha256_sum(struct sha256 *s, uint8_t md[20]) } } -void sha256_update(struct sha256 *s, const void *m, unsigned long len) +static void sha256_update(struct sha256 *s, const void *m, unsigned long len) { const uint8_t *p = m; unsigned r = s->len % 64; -- 2.20.1 From 3f62f76cab46fbd28248ed251a88278c6ea1be3a Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 1 Sep 2012 00:20:24 -0400 Subject: [PATCH 08/16] fix wrong type for poll.h nfds_t this should not break anything since the type should never be used except as the argument type for poll. --- include/poll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/poll.h b/include/poll.h index f868ab57..36ef7fee 100644 --- a/include/poll.h +++ b/include/poll.h @@ -17,7 +17,7 @@ extern "C" { #define POLLWRBAND 0x200 #define POLLMSG 0x400 -typedef unsigned int nfds_t; +typedef unsigned long nfds_t; struct pollfd { -- 2.20.1 From fb247fafa04ee52dda816355ab0461132297b9a4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 2 Sep 2012 12:46:06 -0400 Subject: [PATCH 09/16] avoid "inline" in public headers for strict c89 compatibility while musl itself requires a c99 compiler, some applications insist on being compiled with c89 compilers, and use of "inline" in the headers was breaking them. much of this had been avoided already by just skipping the inline keyword in pre-c99 compilers or modes, but this new unified solution is cleaner and may/should result in better code generation in the default gcc configuration. --- arch/arm/bits/syscall.h | 14 +++++++------- arch/i386/bits/syscall.h | 28 ++++++++++++++-------------- arch/mips/bits/syscall.h | 14 +++++++------- arch/x86_64/bits/syscall.h | 14 +++++++------- include/byteswap.h | 17 ++++++----------- include/endian.h | 19 +++++++------------ include/math.h | 9 +++++---- include/sys/syscall.h | 4 ++++ 8 files changed, 57 insertions(+), 62 deletions(-) diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h index 9932c9e5..c5e25b76 100644 --- a/arch/arm/bits/syscall.h +++ b/arch/arm/bits/syscall.h @@ -7,37 +7,37 @@ long (__syscall)(long, ...); -static inline long __syscall0(long n) +static __inline long __syscall0(long n) { return (__syscall)(n); } -static inline long __syscall1(long n, long a) +static __inline long __syscall1(long n, long a) { return (__syscall)(n, a); } -static inline long __syscall2(long n, long a, long b) +static __inline long __syscall2(long n, long a, long b) { return (__syscall)(n, a, b); } -static inline long __syscall3(long n, long a, long b, long c) +static __inline long __syscall3(long n, long a, long b, long c) { return (__syscall)(n, a, b, c); } -static inline long __syscall4(long n, long a, long b, long c, long d) +static __inline long __syscall4(long n, long a, long b, long c, long d) { return (__syscall)(n, a, b, c, d); } -static inline long __syscall5(long n, long a, long b, long c, long d, long e) +static __inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); } -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) +static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) { return (__syscall)(n, a, b, c, d, e, f); } diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h index 4b574e99..77c7f118 100644 --- a/arch/i386/bits/syscall.h +++ b/arch/i386/bits/syscall.h @@ -5,7 +5,7 @@ #define __SYSCALL_SSLEN 8 -static inline long __syscall0(long __n) +static __inline long __syscall0(long __n) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory"); @@ -14,42 +14,42 @@ static inline long __syscall0(long __n) #ifndef __PIC__ -static inline long __syscall1(long __n, long __a1) +static __inline long __syscall1(long __n, long __a1) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory"); return __ret; } -static inline long __syscall2(long __n, long __a1, long __a2) +static __inline long __syscall2(long __n, long __a1, long __a2) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory"); return __ret; } -static inline long __syscall3(long __n, long __a1, long __a2, long __a3) +static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory"); return __ret; } -static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) +static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory"); return __ret; } -static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) +static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) { unsigned long __ret; __asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory"); return __ret; } -static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) +static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) { unsigned long __ret; __asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx" @@ -59,7 +59,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __ #else -static inline long __syscall1(long __n, long __a1) +static __inline long __syscall1(long __n, long __a1) { unsigned long __ret; __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" @@ -67,7 +67,7 @@ static inline long __syscall1(long __n, long __a1) return __ret; } -static inline long __syscall2(long __n, long __a1, long __a2) +static __inline long __syscall2(long __n, long __a1, long __a2) { unsigned long __ret; __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" @@ -75,7 +75,7 @@ static inline long __syscall2(long __n, long __a1, long __a2) return __ret; } -static inline long __syscall3(long __n, long __a1, long __a2, long __a3) +static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) { unsigned long __ret; __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" @@ -83,7 +83,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3) return __ret; } -static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) +static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) { unsigned long __ret; __asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx" @@ -92,7 +92,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __ } #if 0 -static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) +static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) { unsigned long __ret; __asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx" @@ -100,13 +100,13 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __ return __ret; } #else -static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) +static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) { return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5); } #endif -static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) +static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) { return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6); } diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h index 6c51bab9..9a2de2e3 100644 --- a/arch/mips/bits/syscall.h +++ b/arch/mips/bits/syscall.h @@ -7,37 +7,37 @@ long (__syscall)(long, ...); -static inline long __syscall0(long n) +static __inline long __syscall0(long n) { return (__syscall)(n); } -static inline long __syscall1(long n, long a) +static __inline long __syscall1(long n, long a) { return (__syscall)(n, a); } -static inline long __syscall2(long n, long a, long b) +static __inline long __syscall2(long n, long a, long b) { return (__syscall)(n, a, b); } -static inline long __syscall3(long n, long a, long b, long c) +static __inline long __syscall3(long n, long a, long b, long c) { return (__syscall)(n, a, b, c); } -static inline long __syscall4(long n, long a, long b, long c, long d) +static __inline long __syscall4(long n, long a, long b, long c, long d) { return (__syscall)(n, a, b, c, d); } -static inline long __syscall5(long n, long a, long b, long c, long d, long e) +static __inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); } -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) +static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) { return (__syscall)(n, a, b, c, d, e, f); } diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h index 567cfcb7..217515f3 100644 --- a/arch/x86_64/bits/syscall.h +++ b/arch/x86_64/bits/syscall.h @@ -3,21 +3,21 @@ #define __SYSCALL_SSLEN 8 -static inline long __syscall0(long __n) +static __inline long __syscall0(long __n) { unsigned long __ret; __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory"); return __ret; } -static inline long __syscall1(long __n, long __a1) +static __inline long __syscall1(long __n, long __a1) { unsigned long __ret; __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory"); return __ret; } -static inline long __syscall2(long __n, long __a1, long __a2) +static __inline long __syscall2(long __n, long __a1, long __a2) { unsigned long __ret; __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2) @@ -25,7 +25,7 @@ static inline long __syscall2(long __n, long __a1, long __a2) return __ret; } -static inline long __syscall3(long __n, long __a1, long __a2, long __a3) +static __inline long __syscall3(long __n, long __a1, long __a2, long __a3) { unsigned long __ret; __asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2), @@ -33,7 +33,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3) return __ret; } -static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) +static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4) { unsigned long __ret; register long __r10 __asm__("r10") = __a4; @@ -42,7 +42,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __ return __ret; } -static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) +static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5) { unsigned long __ret; register long __r10 __asm__("r10") = __a4; @@ -52,7 +52,7 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __ return __ret; } -static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) +static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6) { unsigned long __ret; register long __r10 __asm__("r10") = __a4; diff --git a/include/byteswap.h b/include/byteswap.h index 8689cd57..bf222d3c 100644 --- a/include/byteswap.h +++ b/include/byteswap.h @@ -3,26 +3,21 @@ #include -#if __STDC_VERSION__ >= 199901L -inline +#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) +#define __inline inline #endif -static uint16_t __bswap_16(uint16_t __x) + +static __inline uint16_t __bswap_16(uint16_t __x) { return __x<<8 | __x>>8; } -#if __STDC_VERSION__ >= 199901L -inline -#endif -static uint32_t __bswap_32(uint32_t __x) +static __inline uint32_t __bswap_32(uint32_t __x) { return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; } -#if __STDC_VERSION__ >= 199901L -inline -#endif -static uint64_t __bswap_64(uint64_t __x) +static __inline uint64_t __bswap_64(uint64_t __x) { return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); } diff --git a/include/endian.h b/include/endian.h index 41ca1711..528cef31 100644 --- a/include/endian.h +++ b/include/endian.h @@ -1,6 +1,10 @@ #ifndef _ENDIAN_H #define _ENDIAN_H +#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) +#define __inline inline +#endif + #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #define __PDP_ENDIAN 3412 @@ -20,26 +24,17 @@ #include -#if __STDC_VERSION__ >= 199901L -inline -#endif -static uint16_t __bswap16(uint16_t __x) +static __inline uint16_t __bswap16(uint16_t __x) { return __x<<8 | __x>>8; } -#if __STDC_VERSION__ >= 199901L -inline -#endif -static uint32_t __bswap32(uint32_t __x) +static __inline uint32_t __bswap32(uint32_t __x) { return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; } -#if __STDC_VERSION__ >= 199901L -inline -#endif -static uint64_t __bswap64(uint64_t __x) +static __inline uint64_t __bswap64(uint64_t __x) { return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); } diff --git a/include/math.h b/include/math.h index 2fdcb7b4..f808be62 100644 --- a/include/math.h +++ b/include/math.h @@ -5,6 +5,10 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) +#define __inline inline +#endif + #define __NEED_float_t #define __NEED_double_t #define __NEED___uint16_t @@ -83,10 +87,7 @@ int __signbitl(long double); #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) -#if __STDC_VERSION__ >= 199901L -inline -#endif -static int __isrel(long double __x, long double __y, int __rel) +static __inline int __isrel(long double __x, long double __y, int __rel) { if (isunordered(__x, __y)) return 0; if (__rel==-2) return __x < __y; diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 901941aa..154e5ab5 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -4,6 +4,10 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) +#define __inline inline +#endif + long __syscall_ret(unsigned long); long __syscall(long, ...); long syscall(long, ...); -- 2.20.1 From fcfba99503746e44585d7e318562dd425e8ff390 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 20:21:13 -0400 Subject: [PATCH 10/16] fix broken ttyname[_r] (failure to null-terminate result) --- src/unistd/ttyname_r.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unistd/ttyname_r.c b/src/unistd/ttyname_r.c index f86fbd9c..2255e2df 100644 --- a/src/unistd/ttyname_r.c +++ b/src/unistd/ttyname_r.c @@ -15,5 +15,8 @@ int ttyname_r(int fd, char *name, size_t size) if (l < 0) return errno; else if (l == size) return ERANGE; - else return 0; + else { + name[l] = 0; + return 0; + } } -- 2.20.1 From 594318fd3d13c7dda1ea87a76934e052ac74301f Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 20:25:48 -0400 Subject: [PATCH 11/16] remove dependency of memmove on memcpy direction this commit introduces a performance regression in many uses of memmove, which will need to be addressed before the next release. i'm making it as a temporary measure so that the restrict patch can be committed without invoking undefined behavior when memmove calls memcpy with overlapping regions. --- src/string/memmove.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/string/memmove.c b/src/string/memmove.c index 22bb4b35..9153a644 100644 --- a/src/string/memmove.c +++ b/src/string/memmove.c @@ -5,10 +5,9 @@ void *memmove(void *dest, const void *src, size_t n) char *d = dest; const char *s = src; if (d==s) return d; - if ((size_t)(d-s) < n) { + if ((size_t)(d-s) < n) while (n--) d[n] = s[n]; - return dest; - } - /* Assumes memcpy is overlap-safe when dest < src */ - return memcpy(d, s, n); + else + while (n--) *d++ = *s++; + return dest; } -- 2.20.1 From bac03cdde1137c16b4c194e137310e2748661dcc Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 20:28:42 -0400 Subject: [PATCH 12/16] remove dependency of wmemmove on wmemcpy direction unlike the memmove commit, this one should be fine to leave in place. wmemmove is not performance-critical, and even if it were, it's already copying whole 32-bit words at a time instead of bytes. --- src/string/wmemmove.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/string/wmemmove.c b/src/string/wmemmove.c index 49608cae..89041c32 100644 --- a/src/string/wmemmove.c +++ b/src/string/wmemmove.c @@ -3,9 +3,9 @@ wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) { - if ((size_t)(d-s) < n) { + if ((size_t)(d-s) < n) while (n--) d[n] = s[n]; - return d; - } - return wmemcpy(d, s, n); + else + while (n--) *d++ = *s++; + return d; } -- 2.20.1 From 400c5e5c8307a2ebe44ef1f203f5a15669f20347 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 22:44:55 -0400 Subject: [PATCH 13/16] use restrict everywhere it's required by c99 and/or posix 2008 to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict. --- include/aio.h | 8 +- include/arpa/inet.h | 10 ++- include/dirent.h | 8 +- include/dlfcn.h | 8 +- include/glob.h | 8 +- include/iconv.h | 8 +- include/inttypes.h | 14 ++- include/monetary.h | 10 ++- include/mqueue.h | 10 ++- include/netdb.h | 10 ++- include/pthread.h | 60 +++++++------ include/regex.h | 12 ++- include/search.h | 9 +- include/semaphore.h | 10 ++- include/signal.h | 20 +++-- include/spawn.h | 28 +++--- include/stdio.h | 62 +++++++------ include/stdlib.h | 28 +++--- include/string.h | 30 ++++--- include/sys/select.h | 10 ++- include/sys/socket.h | 16 ++-- include/sys/stat.h | 12 ++- include/sys/statvfs.h | 8 +- include/sys/time.h | 10 ++- include/time.h | 22 +++-- include/unistd.h | 12 ++- include/wchar.h | 86 ++++++++++--------- include/wordexp.h | 8 +- src/aio/lio_listio.c | 4 +- src/dirent/readdir_r.c | 2 +- src/ldso/dlsym.c | 4 +- src/ldso/dynlink.c | 4 +- src/locale/iconv.c | 2 +- src/locale/strfmon.c | 4 +- src/locale/strftime_l.c | 2 +- src/locale/strxfrm.c | 2 +- src/locale/strxfrm_l.c | 2 +- src/locale/wcsxfrm.c | 2 +- src/locale/wcsxfrm_l.c | 2 +- src/misc/realpath.c | 2 +- src/misc/wordexp.c | 2 +- src/mq/mq_setattr.c | 2 +- src/mq/mq_timedreceive.c | 2 +- src/multibyte/mbrlen.c | 2 +- src/multibyte/mbrtowc.c | 2 +- src/multibyte/mbsnrtowcs.c | 2 +- src/multibyte/mbsrtowcs.c | 2 +- src/multibyte/mbstowcs.c | 2 +- src/multibyte/mbtowc.c | 2 +- src/multibyte/wcrtomb.c | 2 +- src/multibyte/wcsnrtombs.c | 2 +- src/multibyte/wcsrtombs.c | 2 +- src/multibyte/wcstombs.c | 5 +- src/network/accept.c | 2 +- src/network/getaddrinfo.c | 2 +- src/network/getnameinfo.c | 6 +- src/network/getpeername.c | 2 +- src/network/getsockname.c | 2 +- src/network/getsockopt.c | 2 +- src/network/inet_ntop.c | 2 +- src/network/inet_pton.c | 2 +- src/network/recvfrom.c | 2 +- src/process/posix_spawn.c | 12 +-- .../posix_spawn_file_actions_addopen.c | 2 +- src/process/posix_spawnattr_getflags.c | 2 +- src/process/posix_spawnattr_getpgroup.c | 2 +- src/process/posix_spawnattr_getsigdefault.c | 2 +- src/process/posix_spawnattr_getsigmask.c | 2 +- src/process/posix_spawnattr_setsigdefault.c | 2 +- src/process/posix_spawnattr_setsigmask.c | 2 +- src/process/posix_spawnp.c | 10 +-- src/regex/glob.c | 2 +- src/regex/regcomp.c | 2 +- src/regex/regerror.c | 2 +- src/regex/regexec.c | 4 +- src/select/pselect.c | 2 +- src/select/select.c | 2 +- src/signal/setitimer.c | 2 +- src/signal/sigaction.c | 4 +- src/signal/sigaltstack.c | 2 +- src/signal/sigprocmask.c | 2 +- src/signal/sigtimedwait.c | 2 +- src/signal/sigwait.c | 2 +- src/signal/sigwaitinfo.c | 2 +- src/stat/fstatat.c | 2 +- src/stat/lstat.c | 2 +- src/stat/stat.c | 2 +- src/stat/statvfs.c | 2 +- src/stdio/dprintf.c | 2 +- src/stdio/fgetpos.c | 2 +- src/stdio/fgets.c | 2 +- src/stdio/fgetws.c | 2 +- src/stdio/fmemopen.c | 2 +- src/stdio/fopen.c | 2 +- src/stdio/fprintf.c | 2 +- src/stdio/fputs.c | 2 +- src/stdio/fputws.c | 2 +- src/stdio/fread.c | 2 +- src/stdio/freopen.c | 2 +- src/stdio/fscanf.c | 2 +- src/stdio/fwprintf.c | 2 +- src/stdio/fwrite.c | 4 +- src/stdio/fwscanf.c | 2 +- src/stdio/getdelim.c | 2 +- src/stdio/getline.c | 2 +- src/stdio/printf.c | 2 +- src/stdio/scanf.c | 2 +- src/stdio/setbuf.c | 2 +- src/stdio/setvbuf.c | 2 +- src/stdio/snprintf.c | 2 +- src/stdio/sprintf.c | 2 +- src/stdio/sscanf.c | 2 +- src/stdio/swprintf.c | 2 +- src/stdio/swscanf.c | 2 +- src/stdio/vdprintf.c | 2 +- src/stdio/vfprintf.c | 2 +- src/stdio/vfscanf.c | 2 +- src/stdio/vfwprintf.c | 2 +- src/stdio/vfwscanf.c | 2 +- src/stdio/vprintf.c | 2 +- src/stdio/vscanf.c | 2 +- src/stdio/vsnprintf.c | 2 +- src/stdio/vsprintf.c | 2 +- src/stdio/vsscanf.c | 2 +- src/stdio/vswprintf.c | 2 +- src/stdio/vswscanf.c | 2 +- src/stdio/vwprintf.c | 2 +- src/stdio/vwscanf.c | 2 +- src/stdio/wprintf.c | 2 +- src/stdio/wscanf.c | 2 +- src/stdlib/strtod.c | 6 +- src/stdlib/strtol.c | 12 +-- src/stdlib/wcstod.c | 6 +- src/stdlib/wcstol.c | 12 +-- src/string/memccpy.c | 2 +- src/string/memcpy.c | 2 +- src/string/stpcpy.c | 2 +- src/string/stpncpy.c | 2 +- src/string/strcat.c | 2 +- src/string/strcpy.c | 2 +- src/string/strncat.c | 2 +- src/string/strncpy.c | 2 +- src/string/strtok.c | 2 +- src/string/strtok_r.c | 2 +- src/string/swab.c | 2 +- src/string/wcpcpy.c | 2 +- src/string/wcpncpy.c | 2 +- src/string/wcscat.c | 2 +- src/string/wcscpy.c | 2 +- src/string/wcsncat.c | 2 +- src/string/wcsncpy.c | 2 +- src/string/wcsstr.c | 2 +- src/string/wcstok.c | 2 +- src/string/wmemcpy.c | 2 +- src/thread/pthread_attr_getguardsize.c | 2 +- src/thread/pthread_attr_getschedparam.c | 2 +- src/thread/pthread_attr_getscope.c | 2 +- src/thread/pthread_attr_getstack.c | 2 +- src/thread/pthread_attr_getstacksize.c | 2 +- src/thread/pthread_attr_setschedparam.c | 2 +- src/thread/pthread_barrier_init.c | 2 +- src/thread/pthread_barrierattr_getpshared.c | 2 +- src/thread/pthread_cond_init.c | 2 +- src/thread/pthread_cond_timedwait.c | 2 +- src/thread/pthread_cond_wait.c | 2 +- src/thread/pthread_condattr_getclock.c | 2 +- src/thread/pthread_condattr_getpshared.c | 2 +- src/thread/pthread_create.c | 2 +- src/thread/pthread_mutex_init.c | 2 +- src/thread/pthread_mutex_timedlock.c | 2 +- src/thread/pthread_mutexattr_getpshared.c | 2 +- src/thread/pthread_mutexattr_getrobust.c | 2 +- src/thread/pthread_mutexattr_gettype.c | 2 +- src/thread/pthread_rwlock_init.c | 2 +- src/thread/pthread_rwlock_timedrdlock.c | 2 +- src/thread/pthread_rwlock_timedwrlock.c | 2 +- src/thread/pthread_rwlockattr_getpshared.c | 2 +- src/thread/pthread_sigmask.c | 2 +- src/thread/sem_getvalue.c | 2 +- src/thread/sem_timedwait.c | 2 +- src/time/__asctime.c | 2 +- src/time/asctime_r.c | 4 +- src/time/gettimeofday.c | 2 +- src/time/gmtime_r.c | 2 +- src/time/localtime_r.c | 2 +- src/time/strftime.c | 2 +- src/time/strptime.c | 2 +- src/time/timer_create.c | 2 +- src/time/timer_settime.c | 2 +- src/time/wcsftime.c | 2 +- src/unistd/readlink.c | 2 +- src/unistd/readlinkat.c | 2 +- 192 files changed, 552 insertions(+), 382 deletions(-) diff --git a/include/aio.h b/include/aio.h index 2edd5a2e..3e351348 100644 --- a/include/aio.h +++ b/include/aio.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #include #include @@ -46,7 +52,7 @@ int aio_cancel(int, struct aiocb *); int aio_suspend(const struct aiocb *const [], int, const struct timespec *); int aio_fsync(int, struct aiocb *); -int lio_listio(int, struct aiocb *const [], int, struct sigevent *); +int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict); #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #define aiocb64 aiocb diff --git a/include/arpa/inet.h b/include/arpa/inet.h index b604f60b..82e2ac1b 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #include #include @@ -24,8 +30,8 @@ uint16_t ntohs(uint16_t); in_addr_t inet_addr (const char *); char *inet_ntoa (struct in_addr); -int inet_pton (int, const char *, void *); -const char *inet_ntop (int, const void *, char *, socklen_t); +int inet_pton (int, const char *__restrict, void *__restrict); +const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); int inet_aton (const char *, struct in_addr *); /* nonstandard but widely used */ diff --git a/include/dirent.h b/include/dirent.h index c19f7d58..b6261595 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_ino_t #define __NEED_off_t #ifdef _BSD_SOURCE @@ -30,7 +36,7 @@ int closedir(DIR *); DIR *fdopendir(int); DIR *opendir(const char *); struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); +int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); void rewinddir(DIR *); void seekdir(DIR *, long); long telldir(DIR *); diff --git a/include/dlfcn.h b/include/dlfcn.h index e98c8ca6..2e7d0283 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_GLOBAL 256 @@ -16,7 +22,7 @@ extern "C" { int dlclose(void *); char *dlerror(void); void *dlopen(const char *, int); -void *dlsym(void *, const char *); +void *dlsym(void *__restrict, const char *__restrict); #ifdef _GNU_SOURCE typedef struct { diff --git a/include/glob.h b/include/glob.h index 376baa71..c49a2dea 100644 --- a/include/glob.h +++ b/include/glob.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #include @@ -17,7 +23,7 @@ typedef struct { void *__dummy2[5]; } glob_t; -int glob(const char *, int, int (*)(const char *, int), glob_t *); +int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); void globfree(glob_t *); #define GLOB_ERR 0x01 diff --git a/include/iconv.h b/include/iconv.h index f2ccaf8c..cef06f60 100644 --- a/include/iconv.h +++ b/include/iconv.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #include @@ -12,7 +18,7 @@ extern "C" { typedef void *iconv_t; iconv_t iconv_open(const char *, const char *); -size_t iconv(iconv_t, char **, size_t *, char **, size_t *); +size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); int iconv_close(iconv_t); #ifdef __cplusplus diff --git a/include/inttypes.h b/include/inttypes.h index 13ba6e0f..23acc5be 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -10,16 +10,22 @@ extern "C" { #define __NEED_wchar_t #include +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + typedef struct { intmax_t quot, rem; } imaxdiv_t; intmax_t imaxabs(intmax_t); imaxdiv_t imaxdiv(intmax_t, intmax_t); -intmax_t strtoimax(const char *, char **, int); -uintmax_t strtoumax(const char *, char **, int); +intmax_t strtoimax(const char *__restrict, char **__restrict, int); +uintmax_t strtoumax(const char *__restrict, char **__restrict, int); -intmax_t wcstoimax(const wchar_t *, wchar_t **, int); -uintmax_t wcstoumax(const wchar_t *, wchar_t **, int); +intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); +uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); #if !defined __cplusplus || defined __STDC_FORMAT_MACROS diff --git a/include/monetary.h b/include/monetary.h index df904eb0..11dabb23 100644 --- a/include/monetary.h +++ b/include/monetary.h @@ -5,14 +5,20 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_ssize_t #define __NEED_size_t #define __NEED_locale_t #include -ssize_t strfmon(char *, size_t, const char *, ...); -ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...); +ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...); +ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...); #ifdef __cplusplus } diff --git a/include/mqueue.h b/include/mqueue.h index 92e6ae5e..bd35842c 100644 --- a/include/mqueue.h +++ b/include/mqueue.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #define __NEED_ssize_t #define __NEED_pthread_attr_t @@ -23,8 +29,8 @@ int mq_notify(mqd_t, const struct sigevent *); mqd_t mq_open(const char *, int, ...); ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); int mq_send(mqd_t, const char *, size_t, unsigned); -int mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *); -ssize_t mq_timedreceive(mqd_t, char *, size_t, unsigned *, const struct timespec *); +int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict); +ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict); int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *); int mq_unlink(const char *); diff --git a/include/netdb.h b/include/netdb.h index 42a4b682..d915d9d5 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define __NEED_size_t #endif @@ -55,9 +61,9 @@ struct addrinfo #define EAI_SYSTEM -11 #define EAI_OVERFLOW -12 -int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **); +int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); void freeaddrinfo (struct addrinfo *); -int getnameinfo (const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int); +int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); const char *gai_strerror(int); diff --git a/include/pthread.h b/include/pthread.h index d4ffb9ab..417156c8 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_time_t #define __NEED_clockid_t #define __NEED_struct_timespec @@ -71,7 +77,7 @@ extern "C" { #define PTHREAD_BARRIER_SERIAL_THREAD (-1) -int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); +int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); int pthread_detach(pthread_t); void pthread_exit(void *); int pthread_join(pthread_t, void **); @@ -91,29 +97,29 @@ int pthread_cancel(pthread_t); int pthread_once(pthread_once_t *, void (*)(void)); -int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); +int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); int pthread_mutex_lock(pthread_mutex_t *); int pthread_mutex_unlock(pthread_mutex_t *); int pthread_mutex_trylock(pthread_mutex_t *); -int pthread_mutex_timedlock(pthread_mutex_t *, const struct timespec *); +int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); int pthread_mutex_destroy(pthread_mutex_t *); int pthread_mutex_consistent(pthread_mutex_t *); -int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); +int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); int pthread_cond_destroy(pthread_cond_t *); -int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); -int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *); +int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); +int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); int pthread_cond_broadcast(pthread_cond_t *); int pthread_cond_signal(pthread_cond_t *); -int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *); +int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); int pthread_rwlock_destroy(pthread_rwlock_t *); int pthread_rwlock_rdlock(pthread_rwlock_t *); int pthread_rwlock_tryrdlock(pthread_rwlock_t *); -int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *); +int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); int pthread_rwlock_wrlock(pthread_rwlock_t *); int pthread_rwlock_trywrlock(pthread_rwlock_t *); -int pthread_rwlock_timedwrlock(pthread_rwlock_t *, const struct timespec *); +int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); int pthread_rwlock_unlock(pthread_rwlock_t *); int pthread_spin_init(pthread_spinlock_t *, int); @@ -122,7 +128,7 @@ int pthread_spin_lock(pthread_spinlock_t *); int pthread_spin_trylock(pthread_spinlock_t *); int pthread_spin_unlock(pthread_spinlock_t *); -int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned); +int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); int pthread_barrier_destroy(pthread_barrier_t *); int pthread_barrier_wait(pthread_barrier_t *); @@ -134,29 +140,29 @@ int pthread_setspecific(pthread_key_t, const void *); int pthread_attr_init(pthread_attr_t *); int pthread_attr_destroy(pthread_attr_t *); -int pthread_attr_getguardsize(const pthread_attr_t *, size_t *); +int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); int pthread_attr_setguardsize(pthread_attr_t *, size_t); -int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); +int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); int pthread_attr_setstacksize(pthread_attr_t *, size_t); int pthread_attr_getdetachstate(const pthread_attr_t *, int *); int pthread_attr_setdetachstate(pthread_attr_t *, int); -int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *); +int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); int pthread_attr_setstack(pthread_attr_t *, void *, size_t); -int pthread_attr_getscope(const pthread_attr_t *, int *); +int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); int pthread_attr_setscope(pthread_attr_t *, int); -int pthread_attr_getschedpolicy(const pthread_attr_t *, int *); +int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); int pthread_attr_setschedpolicy(pthread_attr_t *, int); -int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *); -int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *); -int pthread_attr_getinheritsched(const pthread_attr_t *, int *); +int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); +int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); +int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); int pthread_attr_setinheritsched(pthread_attr_t *, int); int pthread_mutexattr_destroy(pthread_mutexattr_t *); -int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *, int *); -int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *); +int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); +int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); +int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); +int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); +int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); int pthread_mutexattr_init(pthread_mutexattr_t *); int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); @@ -168,16 +174,16 @@ int pthread_condattr_init(pthread_condattr_t *); int pthread_condattr_destroy(pthread_condattr_t *); int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); int pthread_condattr_setpshared(pthread_condattr_t *, int); -int pthread_condattr_getclock(const pthread_condattr_t *, clockid_t *); -int pthread_condattr_getpshared(const pthread_condattr_t *, int *); +int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); +int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); int pthread_rwlockattr_init(pthread_rwlockattr_t *); int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *); +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); int pthread_barrierattr_destroy(pthread_barrierattr_t *); -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *); +int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); int pthread_barrierattr_init(pthread_barrierattr_t *); int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); diff --git a/include/regex.h b/include/regex.h index d57208a5..b7167b87 100644 --- a/include/regex.h +++ b/include/regex.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #include @@ -47,11 +53,11 @@ typedef struct { #define REG_ENOSYS -1 -int regcomp(regex_t *, const char *, int); -int regexec(const regex_t *, const char *, size_t, regmatch_t [], int); +int regcomp(regex_t *__restrict, const char *__restrict, int); +int regexec(const regex_t *__restrict, const char *__restrict, size_t, regmatch_t *__restrict, int); void regfree(regex_t *); -size_t regerror(int, const regex_t *, char *, size_t); +size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t); #ifdef __cplusplus } diff --git a/include/search.h b/include/search.h index 7c4fc583..680eee75 100644 --- a/include/search.h +++ b/include/search.h @@ -5,6 +5,13 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + + #define __NEED_size_t #include @@ -28,7 +35,7 @@ void *lsearch(const void *, void *, size_t *, size_t, void *lfind(const void *, const void *, size_t *, size_t, int (*)(const void *, const void *)); -void *tdelete(const void *, void **, int(*)(const void *, const void *)); +void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *)); void *tfind(const void *, void *const *, int(*)(const void *, const void *)); void *tsearch(const void *, void **, int (*)(const void *, const void *)); void twalk(const void *, void (*)(const void *, VISIT, int)); diff --git a/include/semaphore.h b/include/semaphore.h index 2e9b8100..724957fb 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_time_t #define __NEED_struct_timespec #include @@ -18,11 +24,11 @@ typedef struct { int sem_close(sem_t *); int sem_destroy(sem_t *); -int sem_getvalue(sem_t *, int *); +int sem_getvalue(sem_t *__restrict, int *__restrict); int sem_init(sem_t *, int, unsigned); sem_t *sem_open(const char *, int, ...); int sem_post(sem_t *); -int sem_timedwait(sem_t *, const struct timespec *); +int sem_timedwait(sem_t *__restrict, const struct timespec *__restrict); int sem_trywait(sem_t *); int sem_unlink(const char *); int sem_wait(sem_t *); diff --git a/include/signal.h b/include/signal.h index d4856a89..e0dae192 100644 --- a/include/signal.h +++ b/include/signal.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) @@ -165,16 +171,16 @@ int sigaddset(sigset_t *, int); int sigdelset(sigset_t *, int); int sigismember(const sigset_t *, int); -int sigprocmask(int, const sigset_t *, sigset_t *); +int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); int sigsuspend(const sigset_t *); -int sigaction(int, const struct sigaction *, struct sigaction *); +int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); int sigpending(sigset_t *); -int sigwait(const sigset_t *, int *); -int sigwaitinfo(const sigset_t *, siginfo_t *); -int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *); +int sigwait(const sigset_t *__restrict, int *__restrict); +int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); +int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); int sigqueue(pid_t, int, const union sigval); -int pthread_sigmask(int, const sigset_t *, sigset_t *); +int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); int pthread_kill(pthread_t, int); void psiginfo(const siginfo_t *, const char *); @@ -184,7 +190,7 @@ void psignal(int, const char *); #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) int killpg(pid_t, int); -int sigaltstack(const stack_t *, stack_t *); +int sigaltstack(const stack_t *__restrict, stack_t *__restrict); int sighold(int); int sigignore(int); int siginterrupt(int, int); diff --git a/include/spawn.h b/include/spawn.h index 99ec6f1d..c934d423 100644 --- a/include/spawn.h +++ b/include/spawn.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_mode_t #define __NEED_pid_t #define __NEED_sigset_t @@ -33,30 +39,30 @@ typedef struct { int __pad[16]; } posix_spawn_file_actions_t; -int posix_spawn(pid_t *, const char *, const posix_spawn_file_actions_t *, - const posix_spawnattr_t *, char *const [], char *const []); -int posix_spawnp(pid_t *, const char *, const posix_spawn_file_actions_t *, - const posix_spawnattr_t *, char *const [], char *const []); +int posix_spawn(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, + const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); +int posix_spawnp(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, + const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); int posix_spawnattr_init(posix_spawnattr_t *); int posix_spawnattr_destroy(posix_spawnattr_t *); int posix_spawnattr_setflags(posix_spawnattr_t *, short); -int posix_spawnattr_getflags(const posix_spawnattr_t *, short *); +int posix_spawnattr_getflags(const posix_spawnattr_t *__restrict, short *__restrict); int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); -int posix_spawnattr_getpgroup(const posix_spawnattr_t *, pid_t *); +int posix_spawnattr_getpgroup(const posix_spawnattr_t *__restrict, pid_t *__restrict); -int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *); -int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *); +int posix_spawnattr_setsigmask(posix_spawnattr_t *__restrict, const sigset_t *__restrict); +int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict, sigset_t *__restrict); -int posix_spawnattr_setsigdefault(posix_spawnattr_t *, const sigset_t *); -int posix_spawnattr_getsigdefault(const posix_spawnattr_t *, sigset_t *); +int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict, const sigset_t *__restrict); +int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict, sigset_t *__restrict); int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); -int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int, const char *, int, mode_t); +int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *__restrict, int, const char *__restrict, int, mode_t); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); diff --git a/include/stdio.h b/include/stdio.h index 9aa2f782..7d3130e2 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_FILE #define __NEED_va_list #define __NEED_size_t @@ -58,8 +64,8 @@ extern FILE *const stderr; #define stdout (stdout) #define stderr (stderr) -FILE *fopen(const char *, const char *); -FILE *freopen(const char *, const char *, FILE *); +FILE *fopen(const char *__restrict, const char *__restrict); +FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); int fclose(FILE *); int remove(const char *); @@ -74,11 +80,11 @@ int fseek(FILE *, long, int); long ftell(FILE *); void rewind(FILE *); -int fgetpos(FILE *, fpos_t *); +int fgetpos(FILE *__restrict, fpos_t *__restrict); int fsetpos(FILE *, const fpos_t *); -size_t fread(void *, size_t, size_t, FILE *); -size_t fwrite(const void *, size_t, size_t, FILE *); +size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); +size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); int fgetc(FILE *); int getc(FILE *); @@ -89,35 +95,35 @@ int fputc(int, FILE *); int putc(int, FILE *); int putchar(int); -char *fgets(char *, int, FILE *); +char *fgets(char *__restrict, int, FILE *__restrict); #if __STDC_VERSION__ < 201112L char *gets(char *); #endif -int fputs(const char *, FILE *); +int fputs(const char *__restrict, FILE *__restrict); int puts(const char *); -int printf(const char *, ...); -int fprintf(FILE *, const char *, ...); -int sprintf(char *, const char *, ...); -int snprintf(char *, size_t, const char *, ...); +int printf(const char *__restrict, ...); +int fprintf(FILE *__restrict, const char *__restrict, ...); +int sprintf(char *__restrict, const char *__restrict, ...); +int snprintf(char *__restrict, size_t, const char *__restrict, ...); -int vprintf(const char *, va_list); -int vfprintf(FILE *, const char *, va_list); -int vsprintf(char *, const char *, va_list); -int vsnprintf(char *, size_t, const char *, va_list); +int vprintf(const char *__restrict, va_list); +int vfprintf(FILE *__restrict, const char *__restrict, va_list); +int vsprintf(char *__restrict, const char *__restrict, va_list); +int vsnprintf(char *__restrict, size_t, const char *__restrict, va_list); -int scanf(const char *, ...); -int fscanf(FILE *, const char *, ...); -int sscanf(const char *, const char *, ...); -int vscanf(const char *, va_list); -int vfscanf(FILE *, const char *, va_list); -int vsscanf(const char *, const char *, va_list); +int scanf(const char *__restrict, ...); +int fscanf(FILE *__restrict, const char *__restrict, ...); +int sscanf(const char *__restrict, const char *__restrict, ...); +int vscanf(const char *__restrict, va_list); +int vfscanf(FILE *__restrict, const char *__restrict, va_list); +int vsscanf(const char *__restrict, const char *__restrict, va_list); void perror(const char *); -int setvbuf(FILE *, char *, int, size_t); -void setbuf(FILE *, char *); +int setvbuf(FILE *__restrict, char *__restrict, int, size_t); +void setbuf(FILE *__restrict, char *__restrict); char *tmpnam(char *); FILE *tmpfile(void); @@ -125,7 +131,7 @@ FILE *tmpfile(void); #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) -FILE *fmemopen(void *, size_t, const char *); +FILE *fmemopen(void *__restrict, size_t, const char *__restrict); FILE *open_memstream(char **, size_t *); FILE *fdopen(int, const char *); FILE *popen(const char *, const char *); @@ -133,8 +139,8 @@ int pclose(FILE *); int fileno(FILE *); int fseeko(FILE *, off_t, int); off_t ftello(FILE *); -int dprintf(int, const char *, ...); -int vdprintf(int, const char *, va_list); +int dprintf(int, const char *__restrict, ...); +int vdprintf(int, const char *__restrict, va_list); void flockfile(FILE *); int ftrylockfile(FILE *); void funlockfile(FILE *); @@ -142,8 +148,8 @@ int getc_unlocked(FILE *); int getchar_unlocked(void); int putc_unlocked(int, FILE *); int putchar_unlocked(int); -ssize_t getdelim(char **, size_t *, int, FILE *); -ssize_t getline(char **, size_t *, FILE *); +ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); +ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); int renameat(int, const char *, int, const char *); char *ctermid(char *); #define L_ctermid 20 diff --git a/include/stdlib.h b/include/stdlib.h index 1749cb3b..14cc71bb 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #undef NULL #ifdef __cplusplus #define NULL 0 @@ -22,14 +28,14 @@ long atol (const char *); long long atoll (const char *); double atof (const char *); -float strtof (const char *, char **); -double strtod (const char *, char **); -long double strtold (const char *, char **); +float strtof (const char *__restrict, char **__restrict); +double strtod (const char *__restrict, char **__restrict); +long double strtold (const char *__restrict, char **__restrict); -long strtol (const char *, char **, int); -unsigned long strtoul (const char *, char **, int); -long long strtoll (const char *, char **, int); -unsigned long long strtoull (const char *, char **, int); +long strtol (const char *__restrict, char **__restrict, int); +unsigned long strtoul (const char *__restrict, char **__restrict, int); +long long strtoll (const char *__restrict, char **__restrict, int); +unsigned long long strtoull (const char *__restrict, char **__restrict, int); int rand (void); void srand (unsigned); @@ -67,10 +73,10 @@ ldiv_t ldiv (long, long); lldiv_t lldiv (long long, long long); int mblen (const char *, size_t); -int mbtowc (wchar_t *, const char *, size_t); +int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); int wctomb (char *, wchar_t); -size_t mbstowcs (wchar_t *, const char *, size_t); -size_t wcstombs (char *, const wchar_t *, size_t); +size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); +size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 @@ -108,7 +114,7 @@ int rand_r (unsigned *); #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) -char *realpath (const char *, char *); +char *realpath (const char *__restrict, char *__restrict); long int random (void); void srandom (unsigned int); char *initstate (unsigned int, char *, size_t); diff --git a/include/string.h b/include/string.h index 24cb1ca3..f96f71ee 100644 --- a/include/string.h +++ b/include/string.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #undef NULL #ifdef __cplusplus #define NULL 0 @@ -21,23 +27,23 @@ extern "C" { #include -void *memcpy (void *, const void *, size_t); +void *memcpy (void *__restrict, const void *__restrict, size_t); void *memmove (void *, const void *, size_t); void *memset (void *, int, size_t); int memcmp (const void *, const void *, size_t); void *memchr (const void *, int, size_t); -char *strcpy (char *, const char *); -char *strncpy (char *, const char *, size_t); +char *strcpy (char *__restrict, const char *__restrict); +char *strncpy (char *__restrict, const char *__restrict, size_t); -char *strcat (char *, const char *); -char *strncat (char *, const char *, size_t); +char *strcat (char *__restrict, const char *__restrict); +char *strncat (char *__restrict, const char *__restrict, size_t); int strcmp (const char *, const char *); int strncmp (const char *, const char *, size_t); int strcoll (const char *, const char *); -size_t strxfrm (char *, const char *, size_t); +size_t strxfrm (char *__restrict, const char *__restrict, size_t); char *strchr (const char *, int); char *strrchr (const char *, int); @@ -46,7 +52,7 @@ size_t strcspn (const char *, const char *); size_t strspn (const char *, const char *); char *strpbrk (const char *, const char *); char *strstr (const char *, const char *); -char *strtok (char *, const char *); +char *strtok (char *__restrict, const char *__restrict); size_t strlen (const char *); @@ -59,22 +65,22 @@ char *strerror (int); #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) -char *strtok_r (char *, const char *, char **); +char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); int strerror_r (int, char *, size_t); -char *stpcpy(char *, const char *); -char *stpncpy(char *, const char *, size_t); +char *stpcpy(char *__restrict, const char *__restrict); +char *stpncpy(char *__restrict, const char *__restrict, size_t); size_t strnlen (const char *, size_t); char *strdup (const char *); char *strndup (const char *, size_t); char *strsignal(int); char *strerror_l (int, locale_t); int strcoll_l (const char *, const char *, locale_t); -size_t strxfrm_l (char *, const char *, size_t, locale_t); +size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); #endif #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) -void *memccpy (void *, const void *, int, size_t); +void *memccpy (void *__restrict, const void *__restrict, int, size_t); #endif #ifdef _BSD_SOURCE diff --git a/include/sys/select.h b/include/sys/select.h index 47d195f4..dd4176dd 100644 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #define __NEED_time_t #define __NEED_suseconds_t @@ -27,8 +33,8 @@ typedef struct #define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) -int select (int, fd_set *, fd_set *, fd_set *, struct timeval *); -int pselect (int, fd_set *, fd_set *, fd_set *, const struct timespec *, const sigset_t *); +int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); +int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); #ifdef __cplusplus diff --git a/include/sys/socket.h b/include/sys/socket.h index a384ca12..7024d232 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_socklen_t #define __NEED_sa_family_t #define __NEED_size_t @@ -232,19 +238,19 @@ int shutdown (int, int); int bind (int, const struct sockaddr *, socklen_t); int connect (int, const struct sockaddr *, socklen_t); int listen (int, int); -int accept (int, struct sockaddr *, socklen_t *); +int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); -int getsockname (int, struct sockaddr *, socklen_t *); -int getpeername (int, struct sockaddr *, socklen_t *); +int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); +int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t send (int, const void *, size_t, int); ssize_t recv (int, void *, size_t, int); ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -ssize_t recvfrom (int, void *, size_t, int, struct sockaddr *, socklen_t *); +ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t sendmsg (int, const struct msghdr *, int); ssize_t recvmsg (int, struct msghdr *, int); -int getsockopt (int, int, int, void *, socklen_t *); +int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); int setsockopt (int, int, int, const void *, socklen_t); int sockatmark (int); diff --git a/include/sys/stat.h b/include/sys/stat.h index 2a7ce233..e16a9682 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -4,6 +4,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_dev_t #define __NEED_ino_t #define __NEED_mode_t @@ -68,10 +74,10 @@ extern "C" { #define UTIME_NOW 0x3fffffff #define UTIME_OMIT 0x3ffffffe -int stat(const char *, struct stat *); +int stat(const char *__restrict, struct stat *__restrict); int fstat(int, struct stat *); -int lstat(const char *, struct stat *); -int fstatat(int, const char *, struct stat *, int); +int lstat(const char *__restrict, struct stat *__restrict); +int fstatat(int, const char *__restrict, struct stat *__restrict, int); int chmod(const char *, mode_t); int fchmod(int, mode_t); int fchmodat(int, const char *, mode_t, int); diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h index 0a3ac9e0..be41c287 100644 --- a/include/sys/statvfs.h +++ b/include/sys/statvfs.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_fsblkcnt_t #define __NEED_fsfilcnt_t #include @@ -26,7 +32,7 @@ struct statvfs { int __reserved[6]; }; -int statvfs (const char *, struct statvfs *); +int statvfs (const char *__restrict, struct statvfs *__restrict); int fstatvfs (int, struct statvfs *); #define ST_RDONLY 1 diff --git a/include/sys/time.h b/include/sys/time.h index 144dd230..bf026432 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -4,9 +4,15 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #include -int gettimeofday (struct timeval *, void *); +int gettimeofday (struct timeval *__restrict, void *__restrict); #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) @@ -22,7 +28,7 @@ struct itimerval }; int getitimer (int, struct itimerval *); -int setitimer (int, const struct itimerval *, struct itimerval *); +int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); int utimes (const char *, const struct timeval [2]); #endif diff --git a/include/time.h b/include/time.h index 3cc0d28a..f24789e4 100644 --- a/include/time.h +++ b/include/time.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #undef NULL #ifdef __cplusplus #define NULL 0 @@ -48,7 +54,7 @@ clock_t clock (void); time_t time (time_t *); double difftime (time_t, time_t); time_t mktime (struct tm *); -size_t strftime (char *, size_t, const char *, const struct tm *); +size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); struct tm *gmtime (const time_t *); struct tm *localtime (const time_t *); char *asctime (const struct tm *); @@ -61,11 +67,11 @@ char *ctime (const time_t *); || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) -size_t strftime_l (char *, size_t, const char *, const struct tm *, locale_t); +size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); -struct tm *gmtime_r (const time_t *, struct tm *); -struct tm *localtime_r (const time_t *, struct tm *); -char *asctime_r (const struct tm *, char *); +struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); +struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); +char *asctime_r (const struct tm *__restrict, char *__restrict); char *ctime_r (const time_t *, char *); void tzset (void); @@ -91,9 +97,9 @@ int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *) int clock_getcpuclockid (pid_t, clockid_t *); struct sigevent; -int timer_create (clockid_t, struct sigevent *, timer_t *); +int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); int timer_delete (timer_t); -int timer_settime (timer_t, int, const struct itimerspec *, struct itimerspec *); +int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); int timer_gettime (timer_t, struct itimerspec *); int timer_getoverrun (timer_t); @@ -101,7 +107,7 @@ int timer_getoverrun (timer_t); #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) -char *strptime (const char *, const char *, struct tm *); +char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); extern int daylight; extern long timezone; extern char *tzname[2]; diff --git a/include/unistd.h b/include/unistd.h index 12d153b8..ecb23f81 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 @@ -52,8 +58,8 @@ int link(const char *, const char *); int linkat(int, const char *, int, const char *, int); int symlink(const char *, const char *); int symlinkat(const char *, int, const char *); -ssize_t readlink(const char *, char *, size_t); -ssize_t readlinkat(int, const char *, char *, size_t); +ssize_t readlink(const char *__restrict, char *__restrict, size_t); +ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); int unlink(const char *); int unlinkat(int, const char *, int); int rmdir(const char *); @@ -141,7 +147,7 @@ void sync(void); pid_t setpgrp(void); char *crypt(const char *, const char *); void encrypt(char *, int); -void swab(const void *, void *, ssize_t); +void swab(const void *__restrict, void *__restrict, ssize_t); #endif #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ diff --git a/include/wchar.h b/include/wchar.h index 12ddd4f4..b1c6b7fa 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_FILE #define __NEED_va_list #define __NEED_size_t @@ -39,17 +45,17 @@ typedef struct unsigned __opaque1, __opaque2; } mbstate_t; -wchar_t *wcscpy (wchar_t *, const wchar_t *); -wchar_t *wcsncpy (wchar_t *, const wchar_t *, size_t); +wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); +wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -wchar_t *wcscat (wchar_t *, const wchar_t *); -wchar_t *wcsncat (wchar_t *, const wchar_t *, size_t); +wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); +wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); int wcscmp (const wchar_t *, const wchar_t *); int wcsncmp (const wchar_t *, const wchar_t *, size_t); int wcscoll(const wchar_t *, const wchar_t *); -size_t wcsxfrm (wchar_t *, const wchar_t *, size_t n); +size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t n); wchar_t *wcschr (const wchar_t *, wchar_t); wchar_t *wcsrchr (const wchar_t *, wchar_t); @@ -58,16 +64,16 @@ size_t wcscspn (const wchar_t *, const wchar_t *); size_t wcsspn (const wchar_t *, const wchar_t *); wchar_t *wcspbrk (const wchar_t *, const wchar_t *); -wchar_t *wcstok (wchar_t *, const wchar_t *, wchar_t **); +wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); size_t wcslen (const wchar_t *); -wchar_t *wcsstr (const wchar_t *, const wchar_t *); +wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); wchar_t *wcswcs (const wchar_t *, const wchar_t *); wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t *, const wchar_t *, size_t); +wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); wchar_t *wmemset (wchar_t *, wchar_t, size_t); @@ -75,44 +81,44 @@ wint_t btowc (int); int wctob (wint_t); int mbsinit (const mbstate_t *); -size_t mbrtowc (wchar_t *, const char *, size_t, mbstate_t *); -size_t wcrtomb (char *, wchar_t, mbstate_t *); +size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); +size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); -size_t mbrlen (const char *, size_t, mbstate_t *); +size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); -size_t mbsrtowcs (wchar_t *, const char **, size_t, mbstate_t *); -size_t wcsrtombs (char *, const wchar_t **, size_t, mbstate_t *); +size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); +size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); -float wcstof (const wchar_t *, wchar_t **); -double wcstod (const wchar_t *, wchar_t **); -long double wcstold (const wchar_t *, wchar_t **); +float wcstof (const wchar_t *__restrict, wchar_t **__restrict); +double wcstod (const wchar_t *__restrict, wchar_t **__restrict); +long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); -long wcstol (const wchar_t *, wchar_t **, int); -unsigned long wcstoul (const wchar_t *, wchar_t **, int); +long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); +unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); -long long wcstoll (const wchar_t *, wchar_t **, int); -unsigned long long wcstoull (const wchar_t *, wchar_t **, int); +long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); +unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); int fwide (FILE *, int); -int wprintf (const wchar_t *, ...); -int fwprintf (FILE *, const wchar_t *, ...); -int swprintf (wchar_t *, size_t, const wchar_t *, ...); +int wprintf (const wchar_t *__restrict, ...); +int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); +int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); -int vwprintf (const wchar_t *, va_list); -int vfwprintf (FILE *, const wchar_t *, va_list); -int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); +int vwprintf (const wchar_t *__restrict, va_list); +int vfwprintf (FILE *__restrict, const wchar_t *__restrict, va_list); +int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, va_list); -int wscanf (const wchar_t *, ...); -int fwscanf (FILE *, const wchar_t *, ...); -int swscanf (const wchar_t *, const wchar_t *, ...); +int wscanf (const wchar_t *__restrict, ...); +int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); +int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); -int vwscanf (const wchar_t *, va_list); -int vfwscanf (FILE *, const wchar_t *, va_list); -int vswscanf (const wchar_t *, const wchar_t *, va_list); +int vwscanf (const wchar_t *__restrict, va_list); +int vfwscanf (FILE *__restrict, const wchar_t *__restrict, va_list); +int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, va_list); wint_t fgetwc (FILE *); wint_t getwc (FILE *); @@ -122,31 +128,31 @@ wint_t fputwc (wchar_t, FILE *); wint_t putwc (wchar_t, FILE *); wint_t putwchar (wchar_t); -wchar_t *fgetws (wchar_t *, int, FILE *); -int fputws (const wchar_t *, FILE *); +wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); +int fputws (const wchar_t *__restrict, FILE *__restrict); wint_t ungetwc (wint_t, FILE *); struct tm; -size_t wcsftime (wchar_t *, size_t, const wchar_t *, const struct tm *); +size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); #undef iswdigit #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) FILE *open_wmemstream(wchar_t **, size_t *); -size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *); -size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *); +size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); +size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); wchar_t *wcsdup(const wchar_t *); size_t wcsnlen (const wchar_t *, size_t); -wchar_t *wcpcpy (wchar_t *, const wchar_t *); -wchar_t *wcpncpy (wchar_t *, const wchar_t *, size_t); +wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); +wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); int wcscasecmp(const wchar_t *, const wchar_t *); int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); -size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t n, locale_t); +size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t n, locale_t); #endif #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) diff --git a/include/wordexp.h b/include/wordexp.h index 0691c8ea..e7eb3255 100644 --- a/include/wordexp.h +++ b/include/wordexp.h @@ -5,6 +5,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + #define __NEED_size_t #include @@ -30,7 +36,7 @@ typedef struct #define WRDE_CMDSUB 4 #define WRDE_SYNTAX 5 -int wordexp (const char *, wordexp_t *, int); +int wordexp (const char *__restrict, wordexp_t *__restrict, int); void wordfree (wordexp_t *); #ifdef __cplusplus diff --git a/src/aio/lio_listio.c b/src/aio/lio_listio.c index 8c851ca3..30f7cc05 100644 --- a/src/aio/lio_listio.c +++ b/src/aio/lio_listio.c @@ -64,7 +64,7 @@ static void *wait_thread(void *p) return 0; } -int lio_listio(int mode, struct aiocb *const cbs[], int cnt, struct sigevent *sev) +int lio_listio(int mode, struct aiocb *restrict const cbs[restrict], int cnt, struct sigevent *restrict sev) { int i, ret; struct lio_state *st=0; @@ -81,7 +81,7 @@ int lio_listio(int mode, struct aiocb *const cbs[], int cnt, struct sigevent *se } st->cnt = cnt; st->sev = sev; - memcpy(st->cbs, cbs, cnt*sizeof *cbs); + memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs); } for (i=0; i -void *__dlsym(void *, const char *, void *); +void *__dlsym(void *restrict, const char *restrict, void *restrict); -void *dlsym(void *p, const char *s) +void *dlsym(void *restrict p, const char *restrict s) { return __dlsym(p, s, 0); } diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c index 93a4b44c..1c181339 100644 --- a/src/ldso/dynlink.c +++ b/src/ldso/dynlink.c @@ -973,7 +973,7 @@ int __dladdr(void *addr, Dl_info *info) return 1; } -void *__dlsym(void *p, const char *s, void *ra) +void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra) { void *res; pthread_rwlock_rdlock(&lock); @@ -986,7 +986,7 @@ void *dlopen(const char *file, int mode) { return 0; } -void *__dlsym(void *p, const char *s, void *ra) +void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra) { return 0; } diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 508d322e..7b341fe9 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -139,7 +139,7 @@ static void put_32(unsigned char *s, unsigned c, int e) #define mbrtowc_utf8 mbrtowc #define wctomb_utf8 wctomb -size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb) +size_t iconv(iconv_t cd0, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb) { size_t x=0; unsigned long cd = (unsigned long)cd0; diff --git a/src/locale/strfmon.c b/src/locale/strfmon.c index 81dfe38f..f510d9a4 100644 --- a/src/locale/strfmon.c +++ b/src/locale/strfmon.c @@ -75,7 +75,7 @@ static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_l return s-s0; } -ssize_t strfmon_l(char *s, size_t n, locale_t loc, const char *fmt, ...) +ssize_t strfmon_l(char *restrict s, size_t n, locale_t loc, const char *restrict fmt, ...) { va_list ap; ssize_t ret; @@ -88,7 +88,7 @@ ssize_t strfmon_l(char *s, size_t n, locale_t loc, const char *fmt, ...) } -ssize_t strfmon(char *s, size_t n, const char *fmt, ...) +ssize_t strfmon(char *restrict s, size_t n, const char *restrict fmt, ...) { va_list ap; ssize_t ret; diff --git a/src/locale/strftime_l.c b/src/locale/strftime_l.c index 70b2f151..f19f5bf3 100644 --- a/src/locale/strftime_l.c +++ b/src/locale/strftime_l.c @@ -1,7 +1,7 @@ #include #include -size_t strftime_l(char *s, size_t n, const char *f, const struct tm *tm, locale_t l) +size_t strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t l) { return strftime(s, n, f, tm); } diff --git a/src/locale/strxfrm.c b/src/locale/strxfrm.c index 8f123399..d40be9e1 100644 --- a/src/locale/strxfrm.c +++ b/src/locale/strxfrm.c @@ -1,7 +1,7 @@ #include /* collate only by code points */ -size_t strxfrm(char *dest, const char *src, size_t n) +size_t strxfrm(char *restrict dest, const char *restrict src, size_t n) { size_t l = strlen(src); if (n > l) strcpy(dest, src); diff --git a/src/locale/strxfrm_l.c b/src/locale/strxfrm_l.c index 78e56554..81a7badf 100644 --- a/src/locale/strxfrm_l.c +++ b/src/locale/strxfrm_l.c @@ -1,6 +1,6 @@ #include -size_t strxfrm_l(char *dest, const char *src, size_t n, locale_t l) +size_t strxfrm_l(char *restrict dest, const char *restrict src, size_t n, locale_t l) { return strxfrm(dest, src, n); } diff --git a/src/locale/wcsxfrm.c b/src/locale/wcsxfrm.c index 5f76e5a7..bfa01b5b 100644 --- a/src/locale/wcsxfrm.c +++ b/src/locale/wcsxfrm.c @@ -1,7 +1,7 @@ #include /* collate only by code points */ -size_t wcsxfrm(wchar_t *dest, const wchar_t *src, size_t n) +size_t wcsxfrm(wchar_t *restrict dest, const wchar_t *restrict src, size_t n) { size_t l = wcslen(src); if (l >= n) { diff --git a/src/locale/wcsxfrm_l.c b/src/locale/wcsxfrm_l.c index 831998e9..66a00193 100644 --- a/src/locale/wcsxfrm_l.c +++ b/src/locale/wcsxfrm_l.c @@ -1,6 +1,6 @@ #include -size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n, locale_t locale) +size_t wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t locale) { return wcsxfrm(dest, src, n); } diff --git a/src/misc/realpath.c b/src/misc/realpath.c index ef156fcf..57568179 100644 --- a/src/misc/realpath.c +++ b/src/misc/realpath.c @@ -6,7 +6,7 @@ #include #include -char *realpath(const char *filename, char *resolved) +char *realpath(const char *restrict filename, char *restrict resolved) { int fd; ssize_t r; diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c index 15adddbe..617706e5 100644 --- a/src/misc/wordexp.c +++ b/src/misc/wordexp.c @@ -147,7 +147,7 @@ static int do_wordexp(const char *s, wordexp_t *we, int flags) return err; } -int wordexp(const char *s, wordexp_t *we, int flags) +int wordexp(const char *restrict s, wordexp_t *restrict we, int flags) { int r, cs; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); diff --git a/src/mq/mq_setattr.c b/src/mq/mq_setattr.c index 9064fa07..eae022e9 100644 --- a/src/mq/mq_setattr.c +++ b/src/mq/mq_setattr.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int mq_setattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old) +int mq_setattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old) { return syscall(SYS_mq_getsetattr, mqd, new, old); } diff --git a/src/mq/mq_timedreceive.c b/src/mq/mq_timedreceive.c index 099f213a..2cef6a86 100644 --- a/src/mq/mq_timedreceive.c +++ b/src/mq/mq_timedreceive.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -ssize_t mq_timedreceive(mqd_t mqd, char *msg, size_t len, unsigned *prio, const struct timespec *at) +ssize_t mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at) { return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, at); } diff --git a/src/multibyte/mbrlen.c b/src/multibyte/mbrlen.c index c9a9f033..c9714ef8 100644 --- a/src/multibyte/mbrlen.c +++ b/src/multibyte/mbrlen.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t mbrlen(const char *s, size_t n, mbstate_t *st) +size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st) { static unsigned internal; return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c index 291537f8..cc497810 100644 --- a/src/multibyte/mbrtowc.c +++ b/src/multibyte/mbrtowc.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st) +size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate_t *restrict st) { static unsigned internal_state; unsigned c; diff --git a/src/multibyte/mbsnrtowcs.c b/src/multibyte/mbsnrtowcs.c index f42e30d9..33457f95 100644 --- a/src/multibyte/mbsnrtowcs.c +++ b/src/multibyte/mbsnrtowcs.c @@ -12,7 +12,7 @@ #include "internal.h" -size_t mbsnrtowcs(wchar_t *wcs, const char **src, size_t n, size_t wn, mbstate_t *st) +size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st) { size_t l, cnt=0, n2; wchar_t *ws, wbuf[256]; diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c index ebf0d6c9..8313d37b 100644 --- a/src/multibyte/mbsrtowcs.c +++ b/src/multibyte/mbsrtowcs.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) +size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st) { unsigned c; const unsigned char *s = (const void *)*src; diff --git a/src/multibyte/mbstowcs.c b/src/multibyte/mbstowcs.c index 23e1d925..5071baf7 100644 --- a/src/multibyte/mbstowcs.c +++ b/src/multibyte/mbstowcs.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t mbstowcs(wchar_t *ws, const char *s, size_t wn) +size_t mbstowcs(wchar_t *restrict ws, const char *restrict s, size_t wn) { mbstate_t st = { 0 }; return mbsrtowcs(ws, (void*)&s, wn, &st); diff --git a/src/multibyte/mbtowc.c b/src/multibyte/mbtowc.c index bdcaeb3c..b5dd7e3c 100644 --- a/src/multibyte/mbtowc.c +++ b/src/multibyte/mbtowc.c @@ -11,7 +11,7 @@ #include "internal.h" -int mbtowc(wchar_t *wc, const char *s, size_t n) +int mbtowc(wchar_t *restrict wc, const char *restrict s, size_t n) { mbstate_t st = { 0 }; n = mbrtowc(wc, s, n, &st); diff --git a/src/multibyte/wcrtomb.c b/src/multibyte/wcrtomb.c index 36180c8f..250649f5 100644 --- a/src/multibyte/wcrtomb.c +++ b/src/multibyte/wcrtomb.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t wcrtomb(char *s, wchar_t wc, mbstate_t *st) +size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) { if (!s) return 1; if ((unsigned)wc < 0x80) { diff --git a/src/multibyte/wcsnrtombs.c b/src/multibyte/wcsnrtombs.c index 70b0cacb..a2e308b3 100644 --- a/src/multibyte/wcsnrtombs.c +++ b/src/multibyte/wcsnrtombs.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t *st) +size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) { size_t l, cnt=0, n2; char *s, buf[256]; diff --git a/src/multibyte/wcsrtombs.c b/src/multibyte/wcsrtombs.c index 3c48d65b..2582ac2f 100644 --- a/src/multibyte/wcsrtombs.c +++ b/src/multibyte/wcsrtombs.c @@ -11,7 +11,7 @@ #include "internal.h" -size_t wcsrtombs(char *s, const wchar_t **ws, size_t n, mbstate_t *st) +size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstate_t *restrict st) { const wchar_t *ws2; char buf[4]; diff --git a/src/multibyte/wcstombs.c b/src/multibyte/wcstombs.c index b9c1b18a..b6ae4732 100644 --- a/src/multibyte/wcstombs.c +++ b/src/multibyte/wcstombs.c @@ -11,7 +11,8 @@ #include "internal.h" -size_t wcstombs(char *s, const wchar_t *ws, size_t n) +size_t wcstombs(char *restrict s, const wchar_t *restrict ws, size_t n) { - return wcsrtombs(s, &ws, n, 0); + const wchar_t * x = ws; + return wcsrtombs(s, &x, n, 0); } diff --git a/src/network/accept.c b/src/network/accept.c index f6b75ba4..521e9ef9 100644 --- a/src/network/accept.c +++ b/src/network/accept.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int accept(int fd, struct sockaddr *addr, socklen_t *len) +int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) { return socketcall_cp(accept, fd, addr, len, 0, 0, 0); } diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c index 83862166..b9e562f7 100644 --- a/src/network/getaddrinfo.c +++ b/src/network/getaddrinfo.c @@ -47,7 +47,7 @@ struct aibuf { /* Extra slots needed for storing canonical name */ #define EXTRA ((256+sizeof(struct aibuf)-1)/sizeof(struct aibuf)) -int getaddrinfo(const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res) +int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) { int flags = hint ? hint->ai_flags : 0; int family = hint ? hint->ai_family : AF_UNSPEC; diff --git a/src/network/getnameinfo.c b/src/network/getnameinfo.c index 0763ca88..3d115c75 100644 --- a/src/network/getnameinfo.c +++ b/src/network/getnameinfo.c @@ -8,9 +8,9 @@ #include #include "__dns.h" -int getnameinfo(const struct sockaddr *sa, socklen_t sl, - char *node, socklen_t nodelen, - char *serv, socklen_t servlen, +int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl, + char *restrict node, socklen_t nodelen, + char *restrict serv, socklen_t servlen, int flags) { char buf[256]; diff --git a/src/network/getpeername.c b/src/network/getpeername.c index 22effdae..6567b451 100644 --- a/src/network/getpeername.c +++ b/src/network/getpeername.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int getpeername(int fd, struct sockaddr *addr, socklen_t *len) +int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) { return socketcall(getpeername, fd, addr, len, 0, 0, 0); } diff --git a/src/network/getsockname.c b/src/network/getsockname.c index 271e3b41..7885fc13 100644 --- a/src/network/getsockname.c +++ b/src/network/getsockname.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int getsockname(int fd, struct sockaddr *addr, socklen_t *len) +int getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) { return socketcall(getsockname, fd, addr, len, 0, 0, 0); } diff --git a/src/network/getsockopt.c b/src/network/getsockopt.c index a9e0a72d..28079d8c 100644 --- a/src/network/getsockopt.c +++ b/src/network/getsockopt.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen) +int getsockopt(int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen) { return socketcall(getsockopt, fd, level, optname, optval, optlen, 0); } diff --git a/src/network/inet_ntop.c b/src/network/inet_ntop.c index 4817187d..76ae556c 100644 --- a/src/network/inet_ntop.c +++ b/src/network/inet_ntop.c @@ -6,7 +6,7 @@ #include #include -const char *inet_ntop(int af, const void *a0, char *s, socklen_t l) +const char *inet_ntop(int af, const void *restrict a0, char *restrict s, socklen_t l) { const unsigned char *a = a0; int i, j, max, best; diff --git a/src/network/inet_pton.c b/src/network/inet_pton.c index bb16fb90..5c4850a6 100644 --- a/src/network/inet_pton.c +++ b/src/network/inet_pton.c @@ -14,7 +14,7 @@ static int hexval(unsigned c) return -1; } -int inet_pton(int af, const char *s, void *a0) +int inet_pton(int af, const char *restrict s, void *restrict a0) { uint16_t ip[8]; unsigned char *a = a0; diff --git a/src/network/recvfrom.c b/src/network/recvfrom.c index 035a15f8..436f3447 100644 --- a/src/network/recvfrom.c +++ b/src/network/recvfrom.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen) +ssize_t recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen) { return socketcall_cp(recvfrom, fd, buf, len, flags, addr, alen); } diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c index 9f2d7423..1120be08 100644 --- a/src/process/posix_spawn.c +++ b/src/process/posix_spawn.c @@ -8,11 +8,11 @@ extern char **environ; -int __posix_spawnx(pid_t *res, const char *path, +int __posix_spawnx(pid_t *restrict res, const char *restrict path, int (*exec)(const char *, char *const *), const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *attr, - char *const argv[], char *const envp[]) + const posix_spawnattr_t *restrict attr, + char *const argv[restrict], char *const envp[restrict]) { pid_t pid; sigset_t oldmask; @@ -89,10 +89,10 @@ int __posix_spawnx(pid_t *res, const char *path, return 0; } -int posix_spawn(pid_t *res, const char *path, +int posix_spawn(pid_t *restrict res, const char *restrict path, const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *attr, - char *const argv[], char *const envp[]) + const posix_spawnattr_t *restrict attr, + char *const argv[restrict], char *const envp[restrict]) { return __posix_spawnx(res, path, execv, fa, attr, argv, envp); } diff --git a/src/process/posix_spawn_file_actions_addopen.c b/src/process/posix_spawn_file_actions_addopen.c index af3ca604..368922c7 100644 --- a/src/process/posix_spawn_file_actions_addopen.c +++ b/src/process/posix_spawn_file_actions_addopen.c @@ -4,7 +4,7 @@ #include #include "fdop.h" -int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *fa, int fd, const char *path, int flags, mode_t mode) +int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode) { struct fdop *op = malloc(sizeof *op + strlen(path) + 1); if (!op) return ENOMEM; diff --git a/src/process/posix_spawnattr_getflags.c b/src/process/posix_spawnattr_getflags.c index 7353d24a..aa635dda 100644 --- a/src/process/posix_spawnattr_getflags.c +++ b/src/process/posix_spawnattr_getflags.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_getflags(const posix_spawnattr_t *attr, short *flags) +int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags) { *flags = attr->__flags; return 0; diff --git a/src/process/posix_spawnattr_getpgroup.c b/src/process/posix_spawnattr_getpgroup.c index 2c72e985..0480527d 100644 --- a/src/process/posix_spawnattr_getpgroup.c +++ b/src/process/posix_spawnattr_getpgroup.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_getpgroup(const posix_spawnattr_t *attr, pid_t *pgrp) +int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgrp) { *pgrp = attr->__pgrp; return 0; diff --git a/src/process/posix_spawnattr_getsigdefault.c b/src/process/posix_spawnattr_getsigdefault.c index 5f0dfb58..a49050aa 100644 --- a/src/process/posix_spawnattr_getsigdefault.c +++ b/src/process/posix_spawnattr_getsigdefault.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_getsigdefault(const posix_spawnattr_t *attr, sigset_t *def) +int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict def) { *def = attr->__def; return 0; diff --git a/src/process/posix_spawnattr_getsigmask.c b/src/process/posix_spawnattr_getsigmask.c index b4490756..f60ad7f3 100644 --- a/src/process/posix_spawnattr_getsigmask.c +++ b/src/process/posix_spawnattr_getsigmask.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_getsigmask(const posix_spawnattr_t *attr, sigset_t *mask) +int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict mask) { *mask = attr->__mask; return 0; diff --git a/src/process/posix_spawnattr_setsigdefault.c b/src/process/posix_spawnattr_setsigdefault.c index a6ddd4d8..56869726 100644 --- a/src/process/posix_spawnattr_setsigdefault.c +++ b/src/process/posix_spawnattr_setsigdefault.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_setsigdefault(posix_spawnattr_t *attr, const sigset_t *def) +int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict def) { attr->__def = *def; return 0; diff --git a/src/process/posix_spawnattr_setsigmask.c b/src/process/posix_spawnattr_setsigmask.c index 6afbf876..f2532f8e 100644 --- a/src/process/posix_spawnattr_setsigmask.c +++ b/src/process/posix_spawnattr_setsigmask.c @@ -1,6 +1,6 @@ #include -int posix_spawnattr_setsigmask(posix_spawnattr_t *attr, const sigset_t *mask) +int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict mask) { attr->__mask = *mask; return 0; diff --git a/src/process/posix_spawnp.c b/src/process/posix_spawnp.c index 04d768d0..91355fb8 100644 --- a/src/process/posix_spawnp.c +++ b/src/process/posix_spawnp.c @@ -1,15 +1,15 @@ #include #include -int __posix_spawnx(pid_t *, const char *, +int __posix_spawnx(pid_t *restrict, const char *restrict, int (*)(const char *, char *const *), const posix_spawn_file_actions_t *, - const posix_spawnattr_t *, char *const [], char *const []); + const posix_spawnattr_t *restrict, char *const *restrict, char *const *restrict); -int posix_spawnp(pid_t *res, const char *file, +int posix_spawnp(pid_t *restrict res, const char *restrict file, const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *attr, - char *const argv[], char *const envp[]) + const posix_spawnattr_t *restrict attr, + char *const argv[restrict], char *const envp[restrict]) { return __posix_spawnx(res, file, execvp, fa, attr, argv, envp); } diff --git a/src/regex/glob.c b/src/regex/glob.c index 3476e010..6c07e6b3 100644 --- a/src/regex/glob.c +++ b/src/regex/glob.c @@ -156,7 +156,7 @@ static int sort(const void *a, const void *b) return strcmp(*(const char **)a, *(const char **)b); } -int glob(const char *pat, int flags, int (*errfunc)(const char *path, int err), glob_t *g) +int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g) { const char *p=pat, *d; struct match head = { .next = NULL }, *tail = &head; diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index 322a5e67..399989e7 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -3091,7 +3091,7 @@ tre_ast_to_tnfa(tre_ast_node_t *node, tre_tnfa_transition_t *transitions, int -regcomp(regex_t *preg, const char *regex, int cflags) +regcomp(regex_t *restrict preg, const char *restrict regex, int cflags) { tre_stack_t *stack; tre_ast_node_t *tree, *tmp_ast_l, *tmp_ast_r; diff --git a/src/regex/regerror.c b/src/regex/regerror.c index 0645b8e7..df4afa4f 100644 --- a/src/regex/regerror.c +++ b/src/regex/regerror.c @@ -26,7 +26,7 @@ static const char messages[] = { "\0Unknown error" }; -size_t regerror(int e, const regex_t *preg, char *buf, size_t size) +size_t regerror(int e, const regex_t *restrict preg, char *restrict buf, size_t size) { const char *s; for (s=messages; e && *s; e--, s+=strlen(s)+1); diff --git a/src/regex/regexec.c b/src/regex/regexec.c index 8107aae7..855cef57 100644 --- a/src/regex/regexec.c +++ b/src/regex/regexec.c @@ -977,8 +977,8 @@ tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, */ int -regexec(const regex_t *preg, const char *string, - size_t nmatch, regmatch_t pmatch[], int eflags) +regexec(const regex_t *restrict preg, const char *restrict string, + size_t nmatch, regmatch_t pmatch[restrict], int eflags) { tre_tnfa_t *tnfa = (void *)preg->TRE_REGEX_T_FIELD; reg_errcode_t status; diff --git a/src/select/pselect.c b/src/select/pselect.c index 48fcefed..50343fb7 100644 --- a/src/select/pselect.c +++ b/src/select/pselect.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int pselect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *ts, const sigset_t *mask) +int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, const struct timespec *restrict ts, const sigset_t *restrict mask) { long data[2] = { (long)mask, __SYSCALL_SSLEN }; struct timespec ts_tmp; diff --git a/src/select/select.c b/src/select/select.c index 696cb288..f93597b5 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv) +int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv) { return syscall_cp(SYS_select, n, rfds, wfds, efds, tv); } diff --git a/src/signal/setitimer.c b/src/signal/setitimer.c index 3b237580..21b1f45d 100644 --- a/src/signal/setitimer.c +++ b/src/signal/setitimer.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -int setitimer(int which, const struct itimerval *new, struct itimerval *old) +int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old) { return syscall(SYS_setitimer, which, new, old); } diff --git a/src/signal/sigaction.c b/src/signal/sigaction.c index e0c58b73..2331dc93 100644 --- a/src/signal/sigaction.c +++ b/src/signal/sigaction.c @@ -11,7 +11,7 @@ void __restore(), __restore_rt(); static pthread_t dummy(void) { return 0; } weak_alias(dummy, __pthread_self_def); -int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old) +int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) { struct k_sigaction ksa; if (sa) { @@ -31,7 +31,7 @@ int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old) return 0; } -int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old) +int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) { if (sig-32U < 3) { errno = EINVAL; diff --git a/src/signal/sigaltstack.c b/src/signal/sigaltstack.c index 550f2f9d..62cb81ad 100644 --- a/src/signal/sigaltstack.c +++ b/src/signal/sigaltstack.c @@ -2,7 +2,7 @@ #include #include "syscall.h" -int sigaltstack(const stack_t *ss, stack_t *old) +int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) { if (ss) { if (ss->ss_size < MINSIGSTKSZ) { diff --git a/src/signal/sigprocmask.c b/src/signal/sigprocmask.c index 67e2b82e..297e20c6 100644 --- a/src/signal/sigprocmask.c +++ b/src/signal/sigprocmask.c @@ -1,7 +1,7 @@ #include #include -int sigprocmask(int how, const sigset_t *set, sigset_t *old) +int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) { int r = pthread_sigmask(how, set, old); if (!r) return r; diff --git a/src/signal/sigtimedwait.c b/src/signal/sigtimedwait.c index f62db2f3..4f8589b5 100644 --- a/src/signal/sigtimedwait.c +++ b/src/signal/sigtimedwait.c @@ -3,7 +3,7 @@ #include "syscall.h" #include "libc.h" -int sigtimedwait(const sigset_t *mask, siginfo_t *si, const struct timespec *timeout) +int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout) { int ret; do ret = syscall_cp(SYS_rt_sigtimedwait, mask, diff --git a/src/signal/sigwait.c b/src/signal/sigwait.c index 9569d6b0..48a855bb 100644 --- a/src/signal/sigwait.c +++ b/src/signal/sigwait.c @@ -1,7 +1,7 @@ #include #include -int sigwait(const sigset_t *mask, int *sig) +int sigwait(const sigset_t *restrict mask, int *restrict sig) { siginfo_t si; if (sigtimedwait(mask, &si, NULL) < 0) diff --git a/src/signal/sigwaitinfo.c b/src/signal/sigwaitinfo.c index e79feb91..c7b164df 100644 --- a/src/signal/sigwaitinfo.c +++ b/src/signal/sigwaitinfo.c @@ -1,7 +1,7 @@ #include #include -int sigwaitinfo(const sigset_t *mask, siginfo_t *si) +int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si) { return sigtimedwait(mask, si, NULL); } diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c index d6b9390c..863d5268 100644 --- a/src/stat/fstatat.c +++ b/src/stat/fstatat.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int fstatat(int fd, const char *path, struct stat *buf, int flag) +int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag) { return syscall(SYS_fstatat, fd, path, buf, flag); } diff --git a/src/stat/lstat.c b/src/stat/lstat.c index 9053d998..8f60358c 100644 --- a/src/stat/lstat.c +++ b/src/stat/lstat.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int lstat(const char *path, struct stat *buf) +int lstat(const char *restrict path, struct stat *restrict buf) { return syscall(SYS_lstat, path, buf); } diff --git a/src/stat/stat.c b/src/stat/stat.c index c5491eb0..c6de7168 100644 --- a/src/stat/stat.c +++ b/src/stat/stat.c @@ -2,7 +2,7 @@ #include "syscall.h" #include "libc.h" -int stat(const char *path, struct stat *buf) +int stat(const char *restrict path, struct stat *restrict buf) { return syscall(SYS_stat, path, buf); } diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c index 5fadb3b4..637bf82f 100644 --- a/src/stat/statvfs.c +++ b/src/stat/statvfs.c @@ -39,7 +39,7 @@ static void fixup(struct statvfs *out, const struct statfs *in) out->f_namemax = in->f_namelen; } -int statvfs(const char *path, struct statvfs *buf) +int statvfs(const char *restrict path, struct statvfs *restrict buf) { struct statfs kbuf; if (__statfs(path, &kbuf)<0) return -1; diff --git a/src/stdio/dprintf.c b/src/stdio/dprintf.c index fa28322f..93082ee7 100644 --- a/src/stdio/dprintf.c +++ b/src/stdio/dprintf.c @@ -1,7 +1,7 @@ #include #include -int dprintf(int fd, const char *fmt, ...) +int dprintf(int fd, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c index 5b663d1e..c3fa0eb0 100644 --- a/src/stdio/fgetpos.c +++ b/src/stdio/fgetpos.c @@ -1,6 +1,6 @@ #include "stdio_impl.h" -int fgetpos(FILE *f, fpos_t *pos) +int fgetpos(FILE *restrict f, fpos_t *restrict pos) { off_t off = __ftello(f); if (off < 0) return -1; diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c index 3135a69a..ee0ac30e 100644 --- a/src/stdio/fgets.c +++ b/src/stdio/fgets.c @@ -2,7 +2,7 @@ #define MIN(a,b) ((a)<(b) ? (a) : (b)) -char *fgets(char *s, int n, FILE *f) +char *fgets(char *restrict s, int n, FILE *restrict f) { char *p = s; unsigned char *z; diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c index 2e76b565..fab9bd0f 100644 --- a/src/stdio/fgetws.c +++ b/src/stdio/fgetws.c @@ -2,7 +2,7 @@ wint_t __fgetwc_unlocked(FILE *); -wchar_t *fgetws(wchar_t *s, int n, FILE *f) +wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) { wchar_t *p = s; diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c index 1b054a97..770fd995 100644 --- a/src/stdio/fmemopen.c +++ b/src/stdio/fmemopen.c @@ -67,7 +67,7 @@ static int mclose(FILE *m) return 0; } -FILE *fmemopen(void *buf, size_t size, const char *mode) +FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) { FILE *f; struct cookie *c; diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 0d5b1af2..560b77e4 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,6 +1,6 @@ #include "stdio_impl.h" -FILE *fopen(const char *filename, const char *mode) +FILE *fopen(const char *restrict filename, const char *restrict mode) { FILE *f; int fd; diff --git a/src/stdio/fprintf.c b/src/stdio/fprintf.c index a220cc10..948743f7 100644 --- a/src/stdio/fprintf.c +++ b/src/stdio/fprintf.c @@ -1,7 +1,7 @@ #include #include -int fprintf(FILE *f, const char *fmt, ...) +int fprintf(FILE *restrict f, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c index e6bdb204..b41bc8c7 100644 --- a/src/stdio/fputs.c +++ b/src/stdio/fputs.c @@ -1,6 +1,6 @@ #include "stdio_impl.h" -int fputs(const char *s, FILE *f) +int fputs(const char *restrict s, FILE *restrict f) { size_t l = strlen(s); if (!l) return 0; diff --git a/src/stdio/fputws.c b/src/stdio/fputws.c index b75f95bc..0b593c08 100644 --- a/src/stdio/fputws.c +++ b/src/stdio/fputws.c @@ -1,6 +1,6 @@ #include "stdio_impl.h" -int fputws(const wchar_t *ws, FILE *f) +int fputws(const wchar_t *restrict ws, FILE *restrict f) { unsigned char buf[BUFSIZ]; size_t l=0; diff --git a/src/stdio/fread.c b/src/stdio/fread.c index 5c235777..3f31af8a 100644 --- a/src/stdio/fread.c +++ b/src/stdio/fread.c @@ -2,7 +2,7 @@ #define MIN(a,b) ((a)<(b) ? (a) : (b)) -size_t fread(void *destv, size_t size, size_t nmemb, FILE *f) +size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) { unsigned char *dest = destv; size_t len = size*nmemb, l = len, k; diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c index b1f8fe71..57c3cd29 100644 --- a/src/stdio/freopen.c +++ b/src/stdio/freopen.c @@ -7,7 +7,7 @@ /* Locking is not necessary because, in the event of failure, the stream * passed to freopen is invalid as soon as freopen is called. */ -FILE *freopen(const char *filename, const char *mode, FILE *f) +FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict f) { int fl; FILE *f2; diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c index 51fc9b30..ff6c7767 100644 --- a/src/stdio/fscanf.c +++ b/src/stdio/fscanf.c @@ -1,7 +1,7 @@ #include #include -int fscanf(FILE *f, const char *fmt, ...) +int fscanf(FILE *restrict f, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/fwprintf.c b/src/stdio/fwprintf.c index 26d9729a..9ce4f010 100644 --- a/src/stdio/fwprintf.c +++ b/src/stdio/fwprintf.c @@ -2,7 +2,7 @@ #include #include -int fwprintf(FILE *f, const wchar_t *fmt, ...) +int fwprintf(FILE *restrict f, const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c index 1b8641ac..8027b306 100644 --- a/src/stdio/fwrite.c +++ b/src/stdio/fwrite.c @@ -1,6 +1,6 @@ #include "stdio_impl.h" -size_t __fwritex(const unsigned char *s, size_t l, FILE *f) +size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) { size_t i=0; @@ -24,7 +24,7 @@ size_t __fwritex(const unsigned char *s, size_t l, FILE *f) return l+i; } -size_t fwrite(const void *src, size_t size, size_t nmemb, FILE *f) +size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f) { size_t k, l = size*nmemb; if (!l) return l; diff --git a/src/stdio/fwscanf.c b/src/stdio/fwscanf.c index a6892cf6..2f30dab4 100644 --- a/src/stdio/fwscanf.c +++ b/src/stdio/fwscanf.c @@ -2,7 +2,7 @@ #include #include -int fwscanf(FILE *f, const wchar_t *fmt, ...) +int fwscanf(FILE *restrict f, const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c index b7e04acb..5015c3a6 100644 --- a/src/stdio/getdelim.c +++ b/src/stdio/getdelim.c @@ -2,7 +2,7 @@ #define MIN(a,b) ((a)<(b) ? (a) : (b)) -ssize_t getdelim(char **s, size_t *n, int delim, FILE *f) +ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restrict f) { char *tmp; unsigned char *z; diff --git a/src/stdio/getline.c b/src/stdio/getline.c index a3a6651b..476d0b09 100644 --- a/src/stdio/getline.c +++ b/src/stdio/getline.c @@ -1,6 +1,6 @@ #include -ssize_t getline(char **s, size_t *n, FILE *f) +ssize_t getline(char **restrict s, size_t *restrict n, FILE *restrict f) { return getdelim(s, n, '\n', f); } diff --git a/src/stdio/printf.c b/src/stdio/printf.c index 7b7c329f..cebfe404 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -1,7 +1,7 @@ #include #include -int printf(const char *fmt, ...) +int printf(const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c index a04a4402..3b35bdce 100644 --- a/src/stdio/scanf.c +++ b/src/stdio/scanf.c @@ -1,7 +1,7 @@ #include #include -int scanf(const char *fmt, ...) +int scanf(const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/setbuf.c b/src/stdio/setbuf.c index 1b98d503..74ad7834 100644 --- a/src/stdio/setbuf.c +++ b/src/stdio/setbuf.c @@ -1,6 +1,6 @@ #include -void setbuf(FILE *f, char *buf) +void setbuf(FILE *restrict f, char *restrict buf) { setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c index 6dea0ebf..541a125f 100644 --- a/src/stdio/setvbuf.c +++ b/src/stdio/setvbuf.c @@ -9,7 +9,7 @@ * In the case of stderr where the preexisting buffer is length 1, it * is not possible to set line buffering or full buffering. */ -int setvbuf(FILE *f, char *buf, int type, size_t size) +int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size) { f->lbf = EOF; diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c index 4071c2f6..771503b2 100644 --- a/src/stdio/snprintf.c +++ b/src/stdio/snprintf.c @@ -1,7 +1,7 @@ #include #include -int snprintf(char *s, size_t n, const char *fmt, ...) +int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c index 6b225409..9dff524c 100644 --- a/src/stdio/sprintf.c +++ b/src/stdio/sprintf.c @@ -1,7 +1,7 @@ #include #include -int sprintf(char *s, const char *fmt, ...) +int sprintf(char *restrict s, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c index a1cea699..b575edf7 100644 --- a/src/stdio/sscanf.c +++ b/src/stdio/sscanf.c @@ -1,7 +1,7 @@ #include #include -int sscanf(const char *s, const char *fmt, ...) +int sscanf(const char *restrict s, const char *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/swprintf.c b/src/stdio/swprintf.c index 5ece97c4..cbf83d23 100644 --- a/src/stdio/swprintf.c +++ b/src/stdio/swprintf.c @@ -2,7 +2,7 @@ #include #include -int swprintf(wchar_t *s, size_t n, const wchar_t *fmt, ...) +int swprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/swscanf.c b/src/stdio/swscanf.c index b66ad03e..1fe3c3d8 100644 --- a/src/stdio/swscanf.c +++ b/src/stdio/swscanf.c @@ -2,7 +2,7 @@ #include #include -int swscanf(const wchar_t *s, const wchar_t *fmt, ...) +int swscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/vdprintf.c b/src/stdio/vdprintf.c index b41a3c74..c35d9b4f 100644 --- a/src/stdio/vdprintf.c +++ b/src/stdio/vdprintf.c @@ -5,7 +5,7 @@ static size_t wrap_write(FILE *f, const unsigned char *buf, size_t len) return __stdio_write(f, buf, len); } -int vdprintf(int fd, const char *fmt, va_list ap) +int vdprintf(int fd, const char *restrict fmt, va_list ap) { FILE f = { .fd = fd, .lbf = EOF, .write = wrap_write, diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index d186d58b..6525938f 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -636,7 +636,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, return 1; } -int vfprintf(FILE *f, const char *fmt, va_list ap) +int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) { va_list ap2; int nl_type[NL_ARGMAX+1] = {0}; diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index 61b0edb1..54d08495 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -71,7 +71,7 @@ static int readwc(int c, wchar_t **wcs, mbstate_t *st) return 0; } -int vfscanf(FILE *f, const char *fmt, va_list ap) +int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) { int width; int size; diff --git a/src/stdio/vfwprintf.c b/src/stdio/vfwprintf.c index 62829806..a42ba195 100644 --- a/src/stdio/vfwprintf.c +++ b/src/stdio/vfwprintf.c @@ -336,7 +336,7 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_ return 1; } -int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap) +int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) { va_list ap2; int nl_type[NL_ARGMAX] = {0}; diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index de74fe0c..b3bc6f3a 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -86,7 +86,7 @@ static int in_set(const wchar_t *set, int c) ((f)->rend && (c)<128U ? *--(f)->rpos : ungetwc((c),(f))) #endif -int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) +int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) { int width; int size; diff --git a/src/stdio/vprintf.c b/src/stdio/vprintf.c index 67b38dac..30d2bffa 100644 --- a/src/stdio/vprintf.c +++ b/src/stdio/vprintf.c @@ -1,6 +1,6 @@ #include -int vprintf(const char *fmt, va_list ap) +int vprintf(const char *restrict fmt, va_list ap) { return vfprintf(stdout, fmt, ap); } diff --git a/src/stdio/vscanf.c b/src/stdio/vscanf.c index 6f55b1c3..6901958a 100644 --- a/src/stdio/vscanf.c +++ b/src/stdio/vscanf.c @@ -1,7 +1,7 @@ #include #include -int vscanf(const char *fmt, va_list ap) +int vscanf(const char *restrict fmt, va_list ap) { return vfscanf(stdin, fmt, ap); } diff --git a/src/stdio/vsnprintf.c b/src/stdio/vsnprintf.c index ba17bd7d..6f19b028 100644 --- a/src/stdio/vsnprintf.c +++ b/src/stdio/vsnprintf.c @@ -10,7 +10,7 @@ static size_t sn_write(FILE *f, const unsigned char *s, size_t l) return l; } -int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) +int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap) { int r; char b; diff --git a/src/stdio/vsprintf.c b/src/stdio/vsprintf.c index 7836ccb2..c57349d4 100644 --- a/src/stdio/vsprintf.c +++ b/src/stdio/vsprintf.c @@ -1,7 +1,7 @@ #include #include -int vsprintf(char *s, const char *fmt, va_list ap) +int vsprintf(char *restrict s, const char *restrict fmt, va_list ap) { return vsnprintf(s, INT_MAX, fmt, ap); } diff --git a/src/stdio/vsscanf.c b/src/stdio/vsscanf.c index fbc15e69..049f4dd0 100644 --- a/src/stdio/vsscanf.c +++ b/src/stdio/vsscanf.c @@ -5,7 +5,7 @@ static size_t do_read(FILE *f, unsigned char *buf, size_t len) return __string_read(f, buf, len); } -int vsscanf(const char *s, const char *fmt, va_list ap) +int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) { FILE f = { .buf = (void *)s, .cookie = (void *)s, diff --git a/src/stdio/vswprintf.c b/src/stdio/vswprintf.c index 8e8f80ce..f3d4fec1 100644 --- a/src/stdio/vswprintf.c +++ b/src/stdio/vswprintf.c @@ -22,7 +22,7 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l) return i<0 ? i : l0; } -int vswprintf(wchar_t *s, size_t n, const wchar_t *fmt, va_list ap) +int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) { int r; FILE f; diff --git a/src/stdio/vswscanf.c b/src/stdio/vswscanf.c index 4c39f806..a205200a 100644 --- a/src/stdio/vswscanf.c +++ b/src/stdio/vswscanf.c @@ -23,7 +23,7 @@ static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) return 1; } -int vswscanf(const wchar_t *s, const wchar_t *fmt, va_list ap) +int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap) { unsigned char buf[256]; FILE f = { diff --git a/src/stdio/vwprintf.c b/src/stdio/vwprintf.c index c1923e62..eeeecdc7 100644 --- a/src/stdio/vwprintf.c +++ b/src/stdio/vwprintf.c @@ -1,7 +1,7 @@ #include #include -int vwprintf(const wchar_t *fmt, va_list ap) +int vwprintf(const wchar_t *restrict fmt, va_list ap) { return vfwprintf(stdout, fmt, ap); } diff --git a/src/stdio/vwscanf.c b/src/stdio/vwscanf.c index 86da0457..9297cf0d 100644 --- a/src/stdio/vwscanf.c +++ b/src/stdio/vwscanf.c @@ -2,7 +2,7 @@ #include #include -int vwscanf(const wchar_t *fmt, va_list ap) +int vwscanf(const wchar_t *restrict fmt, va_list ap) { return vfwscanf(stdin, fmt, ap); } diff --git a/src/stdio/wprintf.c b/src/stdio/wprintf.c index 20ca61a0..342cd979 100644 --- a/src/stdio/wprintf.c +++ b/src/stdio/wprintf.c @@ -2,7 +2,7 @@ #include #include -int wprintf(const wchar_t *fmt, ...) +int wprintf(const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdio/wscanf.c b/src/stdio/wscanf.c index 34b58846..a207cc1b 100644 --- a/src/stdio/wscanf.c +++ b/src/stdio/wscanf.c @@ -2,7 +2,7 @@ #include #include -int wscanf(const wchar_t *fmt, ...) +int wscanf(const wchar_t *restrict fmt, ...) { int ret; va_list ap; diff --git a/src/stdlib/strtod.c b/src/stdlib/strtod.c index 1886efa5..c6f89e79 100644 --- a/src/stdlib/strtod.c +++ b/src/stdlib/strtod.c @@ -16,17 +16,17 @@ static long double strtox(const char *s, char **p, int prec) return y; } -float strtof(const char *s, char **p) +float strtof(const char *restrict s, char **restrict p) { return strtox(s, p, 0); } -double strtod(const char *s, char **p) +double strtod(const char *restrict s, char **restrict p) { return strtox(s, p, 1); } -long double strtold(const char *s, char **p) +long double strtold(const char *restrict s, char **restrict p) { return strtox(s, p, 2); } diff --git a/src/stdlib/strtol.c b/src/stdlib/strtol.c index 4a949cb0..23a2f3b6 100644 --- a/src/stdlib/strtol.c +++ b/src/stdlib/strtol.c @@ -22,32 +22,32 @@ static unsigned long long strtox(const char *s, char **p, int base, unsigned lon return y; } -unsigned long long strtoull(const char *s, char **p, int base) +unsigned long long strtoull(const char *restrict s, char **restrict p, int base) { return strtox(s, p, base, ULLONG_MAX); } -long long strtoll(const char *s, char **p, int base) +long long strtoll(const char *restrict s, char **restrict p, int base) { return strtox(s, p, base, LLONG_MIN); } -unsigned long strtoul(const char *s, char **p, int base) +unsigned long strtoul(const char *restrict s, char **restrict p, int base) { return strtox(s, p, base, ULONG_MAX); } -long strtol(const char *s, char **p, int base) +long strtol(const char *restrict s, char **restrict p, int base) { return strtox(s, p, base, 0UL+LONG_MIN); } -intmax_t strtoimax(const char *s, char **p, int base) +intmax_t strtoimax(const char *restrict s, char **restrict p, int base) { return strtoll(s, p, base); } -uintmax_t strtoumax(const char *s, char **p, int base) +uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) { return strtoull(s, p, base); } diff --git a/src/stdlib/wcstod.c b/src/stdlib/wcstod.c index 5ec45dd7..03670b0b 100644 --- a/src/stdlib/wcstod.c +++ b/src/stdlib/wcstod.c @@ -47,17 +47,17 @@ static long double wcstox(const wchar_t *s, wchar_t **p, int prec) return y; } -float wcstof(const wchar_t *s, wchar_t **p) +float wcstof(const wchar_t *restrict s, wchar_t **restrict p) { return wcstox(s, p, 0); } -double wcstod(const wchar_t *s, wchar_t **p) +double wcstod(const wchar_t *restrict s, wchar_t **restrict p) { return wcstox(s, p, 1); } -long double wcstold(const wchar_t *s, wchar_t **p) +long double wcstold(const wchar_t *restrict s, wchar_t **restrict p) { return wcstox(s, p, 2); } diff --git a/src/stdlib/wcstol.c b/src/stdlib/wcstol.c index 840bb0a6..3d7c97da 100644 --- a/src/stdlib/wcstol.c +++ b/src/stdlib/wcstol.c @@ -47,32 +47,32 @@ static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsign return y; } -unsigned long long wcstoull(const wchar_t *s, wchar_t **p, int base) +unsigned long long wcstoull(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstox(s, p, base, ULLONG_MAX); } -long long wcstoll(const wchar_t *s, wchar_t **p, int base) +long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstox(s, p, base, LLONG_MIN); } -unsigned long wcstoul(const wchar_t *s, wchar_t **p, int base) +unsigned long wcstoul(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstox(s, p, base, ULONG_MAX); } -long wcstol(const wchar_t *s, wchar_t **p, int base) +long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstox(s, p, base, 0UL+LONG_MIN); } -intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base) +intmax_t wcstoimax(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstoll(s, p, base); } -uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base) +uintmax_t wcstoumax(const wchar_t *restrict s, wchar_t **restrict p, int base) { return wcstoull(s, p, base); } diff --git a/src/string/memccpy.c b/src/string/memccpy.c index 2ccb31bb..b85009c8 100644 --- a/src/string/memccpy.c +++ b/src/string/memccpy.c @@ -8,7 +8,7 @@ #define HIGHS (ONES * (UCHAR_MAX/2+1)) #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) -void *memccpy(void *dest, const void *src, int c, size_t n) +void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) { unsigned char *d = dest; const unsigned char *s = src; diff --git a/src/string/memcpy.c b/src/string/memcpy.c index 02cb4694..8e98302f 100644 --- a/src/string/memcpy.c +++ b/src/string/memcpy.c @@ -6,7 +6,7 @@ #define ALIGN (sizeof(size_t)-1) #define ONES ((size_t)-1/UCHAR_MAX) -void *memcpy(void *dest, const void *src, size_t n) +void *memcpy(void *restrict dest, const void *restrict src, size_t n) { unsigned char *d = dest; const unsigned char *s = src; diff --git a/src/string/stpcpy.c b/src/string/stpcpy.c index 10ca4933..da96f215 100644 --- a/src/string/stpcpy.c +++ b/src/string/stpcpy.c @@ -9,7 +9,7 @@ #define HIGHS (ONES * (UCHAR_MAX/2+1)) #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) -char *__stpcpy(char *d, const char *s) +char *__stpcpy(char *restrict d, const char *restrict s) { size_t *wd; const size_t *ws; diff --git a/src/string/stpncpy.c b/src/string/stpncpy.c index a04cdce8..0a2c2a9d 100644 --- a/src/string/stpncpy.c +++ b/src/string/stpncpy.c @@ -9,7 +9,7 @@ #define HIGHS (ONES * (UCHAR_MAX/2+1)) #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) -char *__stpncpy(char *d, const char *s, size_t n) +char *__stpncpy(char *restrict d, const char *restrict s, size_t n) { size_t *wd; const size_t *ws; diff --git a/src/string/strcat.c b/src/string/strcat.c index 29fdb611..33f749b1 100644 --- a/src/string/strcat.c +++ b/src/string/strcat.c @@ -1,6 +1,6 @@ #include -char *strcat(char *dest, const char *src) +char *strcat(char *restrict dest, const char *restrict src) { strcpy(dest + strlen(dest), src); return dest; diff --git a/src/string/strcpy.c b/src/string/strcpy.c index 7675e9ce..f7e3ba38 100644 --- a/src/string/strcpy.c +++ b/src/string/strcpy.c @@ -2,7 +2,7 @@ char *__stpcpy(char *, const char *); -char *strcpy(char *dest, const char *src) +char *strcpy(char *restrict dest, const char *restrict src) { #if 1 __stpcpy(dest, src); diff --git a/src/string/strncat.c b/src/string/strncat.c index 08685ad6..01ca2a23 100644 --- a/src/string/strncat.c +++ b/src/string/strncat.c @@ -1,6 +1,6 @@ #include -char *strncat(char *d, const char *s, size_t n) +char *strncat(char *restrict d, const char *restrict s, size_t n) { char *a = d; d += strlen(d); diff --git a/src/string/strncpy.c b/src/string/strncpy.c index c0cd7974..441ba033 100644 --- a/src/string/strncpy.c +++ b/src/string/strncpy.c @@ -2,7 +2,7 @@ char *__stpncpy(char *, const char *, size_t); -char *strncpy(char *d, const char *s, size_t n) +char *strncpy(char *restrict d, const char *restrict s, size_t n) { __stpncpy(d, s, n); return d; diff --git a/src/string/strtok.c b/src/string/strtok.c index 1ba221cb..35087902 100644 --- a/src/string/strtok.c +++ b/src/string/strtok.c @@ -1,6 +1,6 @@ #include -char *strtok(char *s, const char *sep) +char *strtok(char *restrict s, const char *restrict sep) { static char *p; if (!s && !(s = p)) return NULL; diff --git a/src/string/strtok_r.c b/src/string/strtok_r.c index c763897a..862d4fe4 100644 --- a/src/string/strtok_r.c +++ b/src/string/strtok_r.c @@ -1,6 +1,6 @@ #include -char *strtok_r(char *s, const char *sep, char **p) +char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p) { if (!s && !(s = *p)) return NULL; s += strspn(s, sep); diff --git a/src/string/swab.c b/src/string/swab.c index b2132884..9ed6fcda 100644 --- a/src/string/swab.c +++ b/src/string/swab.c @@ -1,6 +1,6 @@ #include -void swab(const void *_src, void *_dest, ssize_t n) +void swab(const void *restrict _src, void *restrict _dest, ssize_t n) { const char *src = _src; char *dest = _dest; diff --git a/src/string/wcpcpy.c b/src/string/wcpcpy.c index fdf878f6..ef401343 100644 --- a/src/string/wcpcpy.c +++ b/src/string/wcpcpy.c @@ -1,6 +1,6 @@ #include -wchar_t *wcpcpy(wchar_t *d, const wchar_t *s) +wchar_t *wcpcpy(wchar_t *restrict d, const wchar_t *restrict s) { return wcscpy(d, s) + wcslen(s); } diff --git a/src/string/wcpncpy.c b/src/string/wcpncpy.c index aef80962..b667f6d6 100644 --- a/src/string/wcpncpy.c +++ b/src/string/wcpncpy.c @@ -1,6 +1,6 @@ #include -wchar_t *wcpncpy(wchar_t *d, const wchar_t *s, size_t n) +wchar_t *wcpncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) { return wcsncpy(d, s, n) + wcsnlen(s, n); } diff --git a/src/string/wcscat.c b/src/string/wcscat.c index 946f16e2..d4f00ebd 100644 --- a/src/string/wcscat.c +++ b/src/string/wcscat.c @@ -1,6 +1,6 @@ #include -wchar_t *wcscat(wchar_t *dest, const wchar_t *src) +wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src) { wcscpy(dest + wcslen(dest), src); return dest; diff --git a/src/string/wcscpy.c b/src/string/wcscpy.c index e0ac194f..625bf53d 100644 --- a/src/string/wcscpy.c +++ b/src/string/wcscpy.c @@ -1,6 +1,6 @@ #include -wchar_t *wcscpy(wchar_t *d, const wchar_t *s) +wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s) { wchar_t *a = d; while ((*d++ = *s++)); diff --git a/src/string/wcsncat.c b/src/string/wcsncat.c index 9d61bbbd..8563f1a2 100644 --- a/src/string/wcsncat.c +++ b/src/string/wcsncat.c @@ -1,6 +1,6 @@ #include -wchar_t *wcsncat(wchar_t *d, const wchar_t *s, size_t n) +wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n) { wchar_t *a = d; d += wcslen(d); diff --git a/src/string/wcsncpy.c b/src/string/wcsncpy.c index 714eeb64..4bede04d 100644 --- a/src/string/wcsncpy.c +++ b/src/string/wcsncpy.c @@ -1,6 +1,6 @@ #include -wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) +wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) { wchar_t *a = d; while (n && *s) n--, *d++ = *s++; diff --git a/src/string/wcsstr.c b/src/string/wcsstr.c index fc4bacec..037d0965 100644 --- a/src/string/wcsstr.c +++ b/src/string/wcsstr.c @@ -93,7 +93,7 @@ static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) } } -wchar_t *wcsstr(const wchar_t *h, const wchar_t *n) +wchar_t *wcsstr(const wchar_t *restrict h, const wchar_t *restrict n) { /* Return immediately on empty needle or haystack */ if (!n[0]) return (wchar_t *)h; diff --git a/src/string/wcstok.c b/src/string/wcstok.c index c932d0a0..ecc80331 100644 --- a/src/string/wcstok.c +++ b/src/string/wcstok.c @@ -1,6 +1,6 @@ #include -wchar_t *wcstok(wchar_t *s, const wchar_t *sep, wchar_t **p) +wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep, wchar_t **restrict p) { if (!s && !(s = *p)) return NULL; s += wcsspn(s, sep); diff --git a/src/string/wmemcpy.c b/src/string/wmemcpy.c index 330e37c7..55a8e1d8 100644 --- a/src/string/wmemcpy.c +++ b/src/string/wmemcpy.c @@ -1,7 +1,7 @@ #include #include -wchar_t *wmemcpy(wchar_t *d, const wchar_t *s, size_t n) +wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) { wchar_t *a = d; while (n--) *d++ = *s++; diff --git a/src/thread/pthread_attr_getguardsize.c b/src/thread/pthread_attr_getguardsize.c index 71133f80..93ba05dd 100644 --- a/src/thread/pthread_attr_getguardsize.c +++ b/src/thread/pthread_attr_getguardsize.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_getguardsize(const pthread_attr_t *a, size_t *size) +int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) { *size = a->_a_guardsize + DEFAULT_GUARD_SIZE; return 0; diff --git a/src/thread/pthread_attr_getschedparam.c b/src/thread/pthread_attr_getschedparam.c index 804f6f0f..5806bdf1 100644 --- a/src/thread/pthread_attr_getschedparam.c +++ b/src/thread/pthread_attr_getschedparam.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_getschedparam(const pthread_attr_t *a, struct sched_param *param) +int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) { param->sched_priority = 0; return 0; diff --git a/src/thread/pthread_attr_getscope.c b/src/thread/pthread_attr_getscope.c index fc42a52f..c0167b6a 100644 --- a/src/thread/pthread_attr_getscope.c +++ b/src/thread/pthread_attr_getscope.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_getscope(const pthread_attr_t *a, int *scope) +int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) { return 0; } diff --git a/src/thread/pthread_attr_getstack.c b/src/thread/pthread_attr_getstack.c index 07ac5926..70adbb03 100644 --- a/src/thread/pthread_attr_getstack.c +++ b/src/thread/pthread_attr_getstack.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_getstack(const pthread_attr_t *a, void **addr, size_t *size) +int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) { if (!a->_a_stackaddr) return EINVAL; diff --git a/src/thread/pthread_attr_getstacksize.c b/src/thread/pthread_attr_getstacksize.c index 9575203d..f69cc1e6 100644 --- a/src/thread/pthread_attr_getstacksize.c +++ b/src/thread/pthread_attr_getstacksize.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_getstacksize(const pthread_attr_t *a, size_t *size) +int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) { *size = a->_a_stacksize + DEFAULT_STACK_SIZE; return 0; diff --git a/src/thread/pthread_attr_setschedparam.c b/src/thread/pthread_attr_setschedparam.c index b305f2fa..77ce9c98 100644 --- a/src/thread/pthread_attr_setschedparam.c +++ b/src/thread/pthread_attr_setschedparam.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_attr_setschedparam(pthread_attr_t *a, const struct sched_param *param) +int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param) { if (param->sched_priority) return ENOTSUP; return 0; diff --git a/src/thread/pthread_barrier_init.c b/src/thread/pthread_barrier_init.c index ccaab4eb..01e8cd6b 100644 --- a/src/thread/pthread_barrier_init.c +++ b/src/thread/pthread_barrier_init.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *a, unsigned count) +int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count) { if (count-1 > INT_MAX-1) return EINVAL; *b = (pthread_barrier_t){ ._b_limit = count-1 | (a?*a:0) }; diff --git a/src/thread/pthread_barrierattr_getpshared.c b/src/thread/pthread_barrierattr_getpshared.c index 8428bbec..df337c29 100644 --- a/src/thread/pthread_barrierattr_getpshared.c +++ b/src/thread/pthread_barrierattr_getpshared.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *a, int *pshared) +int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) { *pshared = !!*a; return 0; diff --git a/src/thread/pthread_cond_init.c b/src/thread/pthread_cond_init.c index 03aff768..2eac30f1 100644 --- a/src/thread/pthread_cond_init.c +++ b/src/thread/pthread_cond_init.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a) +int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a) { memset(c, 0, sizeof *c); if (a) { diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c index 1d0f578c..1f25c8e7 100644 --- a/src/thread/pthread_cond_timedwait.c +++ b/src/thread/pthread_cond_timedwait.c @@ -36,7 +36,7 @@ static void cleanup(void *p) pthread_mutex_lock(cm->m); } -int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *ts) +int pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts) { struct cm cm = { .c=c, .m=m }; int r, e=0, seq; diff --git a/src/thread/pthread_cond_wait.c b/src/thread/pthread_cond_wait.c index eb70e5f7..8735bf14 100644 --- a/src/thread/pthread_cond_wait.c +++ b/src/thread/pthread_cond_wait.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m) +int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m) { return pthread_cond_timedwait(c, m, 0); } diff --git a/src/thread/pthread_condattr_getclock.c b/src/thread/pthread_condattr_getclock.c index a77cc3e0..d2933843 100644 --- a/src/thread/pthread_condattr_getclock.c +++ b/src/thread/pthread_condattr_getclock.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_condattr_getclock(const pthread_condattr_t *a, clockid_t *clk) +int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) { *clk = *a & 0x7fffffff; return 0; diff --git a/src/thread/pthread_condattr_getpshared.c b/src/thread/pthread_condattr_getpshared.c index b620976c..4991e495 100644 --- a/src/thread/pthread_condattr_getpshared.c +++ b/src/thread/pthread_condattr_getpshared.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_condattr_getpshared(const pthread_condattr_t *a, int *pshared) +int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) { *pshared = *a>>31; return 0; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 52b48d6f..4567b41c 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -84,7 +84,7 @@ static void init_file_lock(FILE *f) if (f && f->lock<0) f->lock = 0; } -int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(void *), void *arg) +int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attr, void *(*entry)(void *), void *restrict arg) { int ret; size_t size = DEFAULT_STACK_SIZE + DEFAULT_GUARD_SIZE; diff --git a/src/thread/pthread_mutex_init.c b/src/thread/pthread_mutex_init.c index 75ddf02b..fb689271 100644 --- a/src/thread/pthread_mutex_init.c +++ b/src/thread/pthread_mutex_init.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a) +int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a) { memset(m, 0, sizeof *m); if (a) m->_m_type = *a & 7; diff --git a/src/thread/pthread_mutex_timedlock.c b/src/thread/pthread_mutex_timedlock.c index 44bd4bbe..c24270d8 100644 --- a/src/thread/pthread_mutex_timedlock.c +++ b/src/thread/pthread_mutex_timedlock.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *at) +int pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) { int r, t; diff --git a/src/thread/pthread_mutexattr_getpshared.c b/src/thread/pthread_mutexattr_getpshared.c index 3e0438b3..e7340b1a 100644 --- a/src/thread/pthread_mutexattr_getpshared.c +++ b/src/thread/pthread_mutexattr_getpshared.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *a, int *pshared) +int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) { *pshared = *a>>31; return 0; diff --git a/src/thread/pthread_mutexattr_getrobust.c b/src/thread/pthread_mutexattr_getrobust.c index b83cb7c6..4d176f20 100644 --- a/src/thread/pthread_mutexattr_getrobust.c +++ b/src/thread/pthread_mutexattr_getrobust.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *a, int *robust) +int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) { *robust = *a / 4U % 2; return 0; diff --git a/src/thread/pthread_mutexattr_gettype.c b/src/thread/pthread_mutexattr_gettype.c index 9edb16c6..7688b068 100644 --- a/src/thread/pthread_mutexattr_gettype.c +++ b/src/thread/pthread_mutexattr_gettype.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type) +int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) { *type = *a & 3; return 0; diff --git a/src/thread/pthread_rwlock_init.c b/src/thread/pthread_rwlock_init.c index f87d566c..29003bc6 100644 --- a/src/thread/pthread_rwlock_init.c +++ b/src/thread/pthread_rwlock_init.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_rwlock_init(pthread_rwlock_t *rw, const pthread_rwlockattr_t *a) +int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a) { memset(rw, 0, sizeof *rw); if (a) { diff --git a/src/thread/pthread_rwlock_timedrdlock.c b/src/thread/pthread_rwlock_timedrdlock.c index b5cb404a..c0c94c97 100644 --- a/src/thread/pthread_rwlock_timedrdlock.c +++ b/src/thread/pthread_rwlock_timedrdlock.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_rwlock_timedrdlock(pthread_rwlock_t *rw, const struct timespec *at) +int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) { int r, t; while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) { diff --git a/src/thread/pthread_rwlock_timedwrlock.c b/src/thread/pthread_rwlock_timedwrlock.c index aa2fd199..339a1679 100644 --- a/src/thread/pthread_rwlock_timedwrlock.c +++ b/src/thread/pthread_rwlock_timedwrlock.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_rwlock_timedwrlock(pthread_rwlock_t *rw, const struct timespec *at) +int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) { int r, t; while ((r=pthread_rwlock_trywrlock(rw))==EBUSY) { diff --git a/src/thread/pthread_rwlockattr_getpshared.c b/src/thread/pthread_rwlockattr_getpshared.c index 0217bf4e..02fd8c80 100644 --- a/src/thread/pthread_rwlockattr_getpshared.c +++ b/src/thread/pthread_rwlockattr_getpshared.c @@ -1,6 +1,6 @@ #include "pthread_impl.h" -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *a, int *pshared) +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) { *pshared = *(int *)a; return 0; diff --git a/src/thread/pthread_sigmask.c b/src/thread/pthread_sigmask.c index cddc2bca..f6102ad4 100644 --- a/src/thread/pthread_sigmask.c +++ b/src/thread/pthread_sigmask.c @@ -3,7 +3,7 @@ #include #include "syscall.h" -int pthread_sigmask(int how, const sigset_t *set, sigset_t *old) +int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old) { int ret; if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL; diff --git a/src/thread/sem_getvalue.c b/src/thread/sem_getvalue.c index 643c0968..d9d83071 100644 --- a/src/thread/sem_getvalue.c +++ b/src/thread/sem_getvalue.c @@ -1,6 +1,6 @@ #include -int sem_getvalue(sem_t *sem, int *valp) +int sem_getvalue(sem_t *restrict sem, int *restrict valp) { int val = sem->__val[0]; *valp = val < 0 ? 0 : val; diff --git a/src/thread/sem_timedwait.c b/src/thread/sem_timedwait.c index 64b4342c..6d0d0114 100644 --- a/src/thread/sem_timedwait.c +++ b/src/thread/sem_timedwait.c @@ -6,7 +6,7 @@ static void cleanup(void *p) a_dec(p); } -int sem_timedwait(sem_t *sem, const struct timespec *at) +int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) { while (sem_trywait(sem)) { int r; diff --git a/src/time/__asctime.c b/src/time/__asctime.c index 7cc4f503..5362f0db 100644 --- a/src/time/__asctime.c +++ b/src/time/__asctime.c @@ -5,7 +5,7 @@ const char *__langinfo(nl_item); -char *__asctime(const struct tm *tm, char *buf) +char *__asctime(const struct tm *restrict tm, char *restrict buf) { /* FIXME: change __langinfo to __C_langinfo once we have locales */ if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", diff --git a/src/time/asctime_r.c b/src/time/asctime_r.c index e51b8804..7dfbb121 100644 --- a/src/time/asctime_r.c +++ b/src/time/asctime_r.c @@ -1,8 +1,8 @@ #include -char *__asctime(const struct tm *, char *); +char *__asctime(const struct tm *restrict, char *restrict); -char *asctime_r(const struct tm *tm, char *buf) +char *asctime_r(const struct tm *restrict tm, char *restrict buf) { return __asctime(tm, buf); } diff --git a/src/time/gettimeofday.c b/src/time/gettimeofday.c index 09afb70b..691f8e90 100644 --- a/src/time/gettimeofday.c +++ b/src/time/gettimeofday.c @@ -2,7 +2,7 @@ #include #include "syscall.h" -int gettimeofday(struct timeval *tv, void *tz) +int gettimeofday(struct timeval *restrict tv, void *restrict tz) { struct timespec ts; if (!tv) return 0; diff --git a/src/time/gmtime_r.c b/src/time/gmtime_r.c index 5b565a65..13a2548f 100644 --- a/src/time/gmtime_r.c +++ b/src/time/gmtime_r.c @@ -2,7 +2,7 @@ #include "__time.h" -struct tm *gmtime_r(const time_t *t, struct tm *result) +struct tm *gmtime_r(const time_t *restrict t, struct tm *restrict result) { __time_to_tm(*t, result); result->tm_isdst = 0; diff --git a/src/time/localtime_r.c b/src/time/localtime_r.c index 2bf10378..389a5917 100644 --- a/src/time/localtime_r.c +++ b/src/time/localtime_r.c @@ -2,7 +2,7 @@ #include "__time.h" -struct tm *localtime_r(const time_t *t, struct tm *result) +struct tm *localtime_r(const time_t *restrict t, struct tm *restrict result) { __tzset(); __time_to_tm(*t - __timezone, result); diff --git a/src/time/strftime.c b/src/time/strftime.c index f1b94631..b69a83a4 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -8,7 +8,7 @@ const char *__langinfo(nl_item); -size_t strftime(char *s, size_t n, const char *f, const struct tm *tm) +size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) { nl_item item; int val; diff --git a/src/time/strptime.c b/src/time/strptime.c index 4c0bb26c..0f66e6c6 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -7,7 +7,7 @@ #include #include -char *strptime(const char *s, const char *f, struct tm *tm) +char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) { int i, w, neg, adj, min, range, *dest; const char *ex; diff --git a/src/time/timer_create.c b/src/time/timer_create.c index 813678a1..560f1a84 100644 --- a/src/time/timer_create.c +++ b/src/time/timer_create.c @@ -76,7 +76,7 @@ static void *start(void *arg) return 0; } -int timer_create(clockid_t clk, struct sigevent *evp, timer_t *res) +int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict res) { static pthread_once_t once = PTHREAD_ONCE_INIT; pthread_t td; diff --git a/src/time/timer_settime.c b/src/time/timer_settime.c index c400d45c..baf5076b 100644 --- a/src/time/timer_settime.c +++ b/src/time/timer_settime.c @@ -1,7 +1,7 @@ #include #include "pthread_impl.h" -int timer_settime(timer_t t, int flags, const struct itimerspec *val, struct itimerspec *old) +int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old) { if ((uintptr_t)t >= 0x100000) t = ((pthread_t)t)->result; return syscall(SYS_timer_settime, (long)t, flags, val, old); diff --git a/src/time/wcsftime.c b/src/time/wcsftime.c index 7db76922..da6c1f8a 100644 --- a/src/time/wcsftime.c +++ b/src/time/wcsftime.c @@ -2,7 +2,7 @@ #include #include -size_t wcsftime(wchar_t *wcs, size_t n, const wchar_t *f, const struct tm *tm) +size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, const struct tm *restrict tm) { size_t k, n0=n; char out[100], in[4]; diff --git a/src/unistd/readlink.c b/src/unistd/readlink.c index 0c6d3861..ec291e3d 100644 --- a/src/unistd/readlink.c +++ b/src/unistd/readlink.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -ssize_t readlink(const char *path, char *buf, size_t bufsize) +ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) { return syscall(SYS_readlink, path, buf, bufsize); } diff --git a/src/unistd/readlinkat.c b/src/unistd/readlinkat.c index e9498650..9af45cd5 100644 --- a/src/unistd/readlinkat.c +++ b/src/unistd/readlinkat.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -ssize_t readlinkat(int fd, const char *path, char *buf, size_t bufsize) +ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) { return syscall(SYS_readlinkat, fd, path, buf, bufsize); } -- 2.20.1 From ac5d085691e5a797a21ae36111aa0b274e1cf4ba Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 22:58:34 -0400 Subject: [PATCH 14/16] dladdr should be available under _BSD_SOURCE as well as _GNU_SOURCE --- include/dlfcn.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dlfcn.h b/include/dlfcn.h index 2e7d0283..53871ee0 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -24,7 +24,7 @@ char *dlerror(void); void *dlopen(const char *, int); void *dlsym(void *__restrict, const char *__restrict); -#ifdef _GNU_SOURCE +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) typedef struct { const char *dli_fname; void *dli_fbase; -- 2.20.1 From c8ea985748a6857ac5db9ef50f9c92e2966c04d5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 23:12:27 -0400 Subject: [PATCH 15/16] add _Noreturn function attribute, with fallback for pre-C11 GNUC --- include/setjmp.h | 9 ++++++++- include/stdlib.h | 15 +++++++++++---- src/exit/_Exit.c | 2 +- src/exit/abort.c | 2 +- src/exit/exit.c | 2 +- src/exit/quick_exit.c | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/setjmp.h b/include/setjmp.h index 7dc72767..8ec5c6f1 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -5,6 +5,13 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + #include @@ -29,7 +36,7 @@ void _longjmp (jmp_buf, int); int setjmp (jmp_buf); -void longjmp (jmp_buf, int); +_Noreturn void longjmp (jmp_buf, int); #define setjmp setjmp #define longjmp longjmp diff --git a/include/stdlib.h b/include/stdlib.h index 14cc71bb..86cf0171 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -11,6 +11,13 @@ extern "C" { #define __restrict #endif +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + #undef NULL #ifdef __cplusplus #define NULL 0 @@ -46,12 +53,12 @@ void *realloc (void *, size_t); void free (void *); void *aligned_alloc(size_t alignment, size_t size); -void abort (void); +_Noreturn void abort (void); int atexit (void (*) (void)); -void exit (int); -void _Exit (int); +_Noreturn void exit (int); +_Noreturn void _Exit (int); int at_quick_exit (void (*) (void)); -void quick_exit (int); +_Noreturn void quick_exit (int); char *getenv (const char *); diff --git a/src/exit/_Exit.c b/src/exit/_Exit.c index 6ceb1437..c00a2ffb 100644 --- a/src/exit/_Exit.c +++ b/src/exit/_Exit.c @@ -1,7 +1,7 @@ #include #include "syscall.h" -void _Exit(int ec) +_Noreturn void _Exit(int ec) { __syscall(SYS_exit_group, ec); __syscall(SYS_exit, ec); diff --git a/src/exit/abort.c b/src/exit/abort.c index c5b9e526..203dd35c 100644 --- a/src/exit/abort.c +++ b/src/exit/abort.c @@ -2,7 +2,7 @@ #include #include "syscall.h" -void abort(void) +_Noreturn void abort(void) { raise(SIGABRT); raise(SIGKILL); diff --git a/src/exit/exit.c b/src/exit/exit.c index e4aeaf15..e4932b5b 100644 --- a/src/exit/exit.c +++ b/src/exit/exit.c @@ -14,7 +14,7 @@ weak_alias(dummy, __funcs_on_exit); weak_alias(dummy, __flush_on_exit); weak_alias(dummy, __seek_on_exit); -void exit(int code) +_Noreturn void exit(int code) { static int lock; diff --git a/src/exit/quick_exit.c b/src/exit/quick_exit.c index 18d5288a..1175d80c 100644 --- a/src/exit/quick_exit.c +++ b/src/exit/quick_exit.c @@ -6,7 +6,7 @@ static void dummy() { } weak_alias(dummy, __funcs_on_quick_exit); -void quick_exit(int code) +_Noreturn void quick_exit(int code) { static int lock; while (a_swap(&lock, 1)) __syscall(SYS_pause); -- 2.20.1 From 453059571c9dc84dd168631eced25ec2d7afd98e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 6 Sep 2012 23:27:55 -0400 Subject: [PATCH 16/16] fix invalid implicit pointer conversion in gnulib-compat functions --- src/stdio/ext2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/ext2.c b/src/stdio/ext2.c index e587d64b..f359be9a 100644 --- a/src/stdio/ext2.c +++ b/src/stdio/ext2.c @@ -10,7 +10,7 @@ const char *__freadptr(FILE *f, size_t *sizep) size_t size = f->rend - f->rpos; if (!size) return 0; *sizep = size; - return f->rpos; + return (const char *)f->rpos; } void __freadptrinc(FILE *f, size_t inc) -- 2.20.1