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.
This commit is contained in:
parent
bac03cdde1
commit
400c5e5c83
192 changed files with 552 additions and 382 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int dprintf(int fd, const char *fmt, ...)
|
||||
int dprintf(int fd, const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int fprintf(FILE *f, const char *fmt, ...)
|
||||
int fprintf(FILE *restrict f, const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int fscanf(FILE *f, const char *fmt, ...)
|
||||
int fscanf(FILE *restrict f, const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int fwprintf(FILE *f, const wchar_t *fmt, ...)
|
||||
int fwprintf(FILE *restrict f, const wchar_t *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int fwscanf(FILE *f, const wchar_t *fmt, ...)
|
||||
int fwscanf(FILE *restrict f, const wchar_t *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int printf(const char *fmt, ...)
|
||||
int printf(const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int scanf(const char *fmt, ...)
|
||||
int scanf(const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void setbuf(FILE *f, char *buf)
|
||||
void setbuf(FILE *restrict f, char *restrict buf)
|
||||
{
|
||||
setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int sprintf(char *s, const char *fmt, ...)
|
||||
int sprintf(char *restrict s, const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int sscanf(const char *s, const char *fmt, ...)
|
||||
int sscanf(const char *restrict s, const char *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int vprintf(const char *fmt, va_list ap)
|
||||
int vprintf(const char *restrict fmt, va_list ap)
|
||||
{
|
||||
return vfprintf(stdout, fmt, ap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int vscanf(const char *fmt, va_list ap)
|
||||
int vscanf(const char *restrict fmt, va_list ap)
|
||||
{
|
||||
return vfscanf(stdin, fmt, ap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int vwprintf(const wchar_t *fmt, va_list ap)
|
||||
int vwprintf(const wchar_t *restrict fmt, va_list ap)
|
||||
{
|
||||
return vfwprintf(stdout, fmt, ap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int vwscanf(const wchar_t *fmt, va_list ap)
|
||||
int vwscanf(const wchar_t *restrict fmt, va_list ap)
|
||||
{
|
||||
return vfwscanf(stdin, fmt, ap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int wprintf(const wchar_t *fmt, ...)
|
||||
int wprintf(const wchar_t *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int wscanf(const wchar_t *fmt, ...)
|
||||
int wscanf(const wchar_t *restrict fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue