From ed68431e9eb5f5d79436afe779c4564cc625c69e Mon Sep 17 00:00:00 2001 From: emaste Date: Tue, 23 Apr 2013 14:36:44 +0000 Subject: Convert libc/stdio from K&R to ANSI C And add '__restrict' where it appeared in the header prototypes --- lib/libc/stdio/clrerr.c | 3 +-- lib/libc/stdio/fdopen.c | 4 +--- lib/libc/stdio/fgetc.c | 3 +-- lib/libc/stdio/fgets.c | 5 +---- lib/libc/stdio/findfp.c | 3 +-- lib/libc/stdio/flags.c | 4 +--- lib/libc/stdio/fopen.c | 4 +--- lib/libc/stdio/fpurge.c | 3 +-- lib/libc/stdio/fputc.c | 4 +--- lib/libc/stdio/fputs.c | 4 +--- lib/libc/stdio/freopen.c | 6 ++---- lib/libc/stdio/fseek.c | 16 +++------------- lib/libc/stdio/fsetpos.c | 4 +--- lib/libc/stdio/ftell.c | 10 +++------- lib/libc/stdio/fvwrite.c | 4 +--- lib/libc/stdio/fwalk.c | 3 +-- lib/libc/stdio/fwrite.c | 5 +---- lib/libc/stdio/gets.c | 3 +-- lib/libc/stdio/getw.c | 3 +-- lib/libc/stdio/makebuf.c | 8 ++------ lib/libc/stdio/mktemp.c | 22 ++++++---------------- lib/libc/stdio/perror.c | 3 +-- lib/libc/stdio/putc.c | 4 +--- lib/libc/stdio/putchar.c | 3 +-- lib/libc/stdio/puts.c | 3 +-- lib/libc/stdio/putw.c | 4 +--- lib/libc/stdio/remove.c | 3 +-- lib/libc/stdio/setbuffer.c | 8 ++------ lib/libc/stdio/stdio.c | 33 +++++++-------------------------- lib/libc/stdio/tempnam.c | 3 +-- lib/libc/stdio/tmpnam.c | 3 +-- lib/libc/stdio/vscanf.c | 9 ++------- lib/libc/stdio/wbuf.c | 4 +--- lib/libc/stdio/wsetup.c | 3 +-- 34 files changed, 53 insertions(+), 151 deletions(-) diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index 3683c10..f161a6e 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -45,8 +45,7 @@ __FBSDID("$FreeBSD$"); #undef clearerr_unlocked void -clearerr(fp) - FILE *fp; +clearerr(FILE *fp) { FLOCKFILE(fp); __sclearerr(fp); diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index 4252c72..2e19b9f 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -47,9 +47,7 @@ __FBSDID("$FreeBSD$"); #include "local.h" FILE * -fdopen(fd, mode) - int fd; - const char *mode; +fdopen(int fd, const char *mode) { FILE *fp; int flags, oflags, fdflags, tmp; diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 0e5e623..2ee4d7a 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -43,8 +43,7 @@ __FBSDID("$FreeBSD$"); #include "local.h" int -fgetc(fp) - FILE *fp; +fgetc(FILE *fp) { int retval; FLOCKFILE(fp); diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index ba2a0e6..9abf559 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -49,10 +49,7 @@ __FBSDID("$FreeBSD$"); * Return first argument, or NULL if no characters were read. */ char * -fgets(buf, n, fp) - char *buf; - int n; - FILE *fp; +fgets(char * __restrict buf, int n, FILE * __restrict fp) { size_t len; char *s; diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index e8dd382..be196b7 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -91,8 +91,7 @@ spinlock_t __stdio_thread_lock = _SPINLOCK_INITIALIZER; #endif static struct glue * -moreglue(n) - int n; +moreglue(int n) { struct glue *g; static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER }; diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index 9546717..1878c2f 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -49,9 +49,7 @@ __FBSDID("$FreeBSD$"); * Return 0 on error. */ int -__sflags(mode, optr) - const char *mode; - int *optr; +__sflags(const char *mode, int *optr) { int ret, m, o; diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 2d85f53..b08e336 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -49,9 +49,7 @@ __FBSDID("$FreeBSD$"); #include "local.h" FILE * -fopen(file, mode) - const char * __restrict file; - const char * __restrict mode; +fopen(const char * __restrict file, const char * __restrict mode) { FILE *fp; int f; diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index 8447729..f205bdf 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$"); * given FILE's buffer empty. */ int -fpurge(fp) - FILE *fp; +fpurge(FILE *fp) { int retval; FLOCKFILE(fp); diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index 75fb131..3b6101f 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -43,9 +43,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" int -fputc(c, fp) - int c; - FILE *fp; +fputc(int c, FILE *fp) { int retval; FLOCKFILE(fp); diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 650adcd..3b8f2c9 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -48,9 +48,7 @@ __FBSDID("$FreeBSD$"); * Write the given string to the given file. */ int -fputs(s, fp) - const char * __restrict s; - FILE * __restrict fp; +fputs(const char * __restrict s, FILE * __restrict fp) { int retval; struct __suio uio; diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 7d8feca..dc5508d 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -55,10 +55,8 @@ __FBSDID("$FreeBSD$"); * all possible, no matter what. */ FILE * -freopen(file, mode, fp) - const char * __restrict file; - const char * __restrict mode; - FILE *fp; +freopen(const char * __restrict file, const char * __restrict mode, + FILE * __restrict fp) { int f; int dflags, flags, isopen, oflags, sverrno, wantfd; diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 55ab657..2897eeb 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -51,10 +51,7 @@ __FBSDID("$FreeBSD$"); #define POS_ERR (-(fpos_t)1) int -fseek(fp, offset, whence) - FILE *fp; - long offset; - int whence; +fseek(FILE *fp, long offset, int whence) { int ret; int serrno = errno; @@ -72,10 +69,7 @@ fseek(fp, offset, whence) } int -fseeko(fp, offset, whence) - FILE *fp; - off_t offset; - int whence; +fseeko(FILE *fp, off_t offset, int whence) { int ret; int serrno = errno; @@ -97,11 +91,7 @@ fseeko(fp, offset, whence) * `Whence' must be one of the three SEEK_* macros. */ int -_fseeko(fp, offset, whence, ltest) - FILE *fp; - off_t offset; - int whence; - int ltest; +_fseeko(FILE *fp, off_t offset, int whence, int ltest) { fpos_t (*seekfn)(void *, fpos_t, int); fpos_t target, curoff, ret; diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c index b56fbba..c6b8b78 100644 --- a/lib/libc/stdio/fsetpos.c +++ b/lib/libc/stdio/fsetpos.c @@ -43,9 +43,7 @@ __FBSDID("$FreeBSD$"); * fsetpos: like fseek. */ int -fsetpos(iop, pos) - FILE *iop; - const fpos_t *pos; +fsetpos(FILE *iop, const fpos_t *pos) { return (fseeko(iop, (off_t)*pos, SEEK_SET)); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 9a1c160..2c8800c 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$"); * standard ftell function. */ long -ftell(fp) - FILE *fp; +ftell(FILE *fp) { off_t rv; @@ -66,8 +65,7 @@ ftell(fp) * ftello: return current offset. */ off_t -ftello(fp) - FILE *fp; +ftello(FILE *fp) { fpos_t rv; int ret; @@ -85,9 +83,7 @@ ftello(fp) } int -_ftello(fp, offset) - FILE *fp; - fpos_t *offset; +_ftello(FILE *fp, fpos_t *offset) { fpos_t pos; size_t n; diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 71c83c2..1a28b6a 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -49,9 +49,7 @@ __FBSDID("$FreeBSD$"); * to the three different kinds of output buffering is handled here. */ int -__sfvwrite(fp, uio) - FILE *fp; - struct __suio *uio; +__sfvwrite(FILE *fp, struct __suio *uio) { size_t len; char *p; diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c index f26ff84..151837b 100644 --- a/lib/libc/stdio/fwalk.c +++ b/lib/libc/stdio/fwalk.c @@ -42,8 +42,7 @@ __FBSDID("$FreeBSD$"); #include "glue.h" int -_fwalk(function) - int (*function)(FILE *); +_fwalk(int (*function)(FILE *)) { FILE *fp; int n, ret; diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 08587c7..707d362 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -50,10 +50,7 @@ __FBSDID("$FreeBSD$"); * Return the number of whole objects written. */ size_t -fwrite(buf, size, count, fp) - const void * __restrict buf; - size_t size, count; - FILE * __restrict fp; +fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) { size_t n; struct __suio uio; diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index 5177318..c7c1c2f 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -47,8 +47,7 @@ __FBSDID("$FreeBSD$"); __warn_references(gets, "warning: this program uses gets(), which is unsafe."); char * -gets(buf) - char *buf; +gets(char *buf) { int c; char *s; diff --git a/lib/libc/stdio/getw.c b/lib/libc/stdio/getw.c index 7d75000..ed0313e 100644 --- a/lib/libc/stdio/getw.c +++ b/lib/libc/stdio/getw.c @@ -39,8 +39,7 @@ __FBSDID("$FreeBSD$"); #include int -getw(fp) - FILE *fp; +getw(FILE *fp) { int x; diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c index 42f77cd..a92087e 100644 --- a/lib/libc/stdio/makebuf.c +++ b/lib/libc/stdio/makebuf.c @@ -55,8 +55,7 @@ __FBSDID("$FreeBSD$"); * optimisation) right after the _fstat() that finds the buffer size. */ void -__smakebuf(fp) - FILE *fp; +__smakebuf(FILE *fp) { void *p; int flags; @@ -88,10 +87,7 @@ __smakebuf(fp) * Internal routine to determine `proper' buffering for a file. */ int -__swhatbuf(fp, bufsize, couldbetty) - FILE *fp; - size_t *bufsize; - int *couldbetty; +__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty) { struct stat st; diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index 24f9a67..58783dd 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -53,9 +53,7 @@ static const unsigned char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int -mkstemps(path, slen) - char *path; - int slen; +mkstemps(char *path, int slen) { int fd; @@ -63,8 +61,7 @@ mkstemps(path, slen) } int -mkstemp(path) - char *path; +mkstemp(char *path) { int fd; @@ -72,15 +69,13 @@ mkstemp(path) } char * -mkdtemp(path) - char *path; +mkdtemp(char *path) { return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); } char * -_mktemp(path) - char *path; +_mktemp(char *path) { return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); } @@ -89,18 +84,13 @@ __warn_references(mktemp, "warning: mktemp() possibly used unsafely; consider using mkstemp()"); char * -mktemp(path) - char *path; +mktemp(char *path) { return (_mktemp(path)); } static int -_gettemp(path, doopen, domkdir, slen) - char *path; - int *doopen; - int domkdir; - int slen; +_gettemp(char *path, int *doopen, int domkdir, int slen) { char *start, *trv, *suffp, *carryp; char *pad; diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index 80f0154..89c0798 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -46,8 +46,7 @@ __FBSDID("$FreeBSD$"); #include "local.h" void -perror(s) - const char *s; +perror(const char *s) { char msgbuf[NL_TEXTMAX]; struct iovec *v; diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index 6b62786..aaffece 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -46,9 +46,7 @@ __FBSDID("$FreeBSD$"); #undef putc_unlocked int -putc(c, fp) - int c; - FILE *fp; +putc(int c, FILE *fp) { int retval; FLOCKFILE(fp); diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 9a17784..7561559 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$"); * A subroutine version of the macro putchar */ int -putchar(c) - int c; +putchar(int c) { int retval; FILE *so = stdout; diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index 31d5135..5ee7fc1 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -48,8 +48,7 @@ __FBSDID("$FreeBSD$"); * Write the given string to stdout, appending a newline. */ int -puts(s) - char const *s; +puts(char const *s) { int retval; size_t c = strlen(s); diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c index 922f9be..0360caf 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -43,9 +43,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" int -putw(w, fp) - int w; - FILE *fp; +putw(int w, FILE *fp) { int retval; struct __suio uio; diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index b237513..2e984ba 100644 --- a/lib/libc/stdio/remove.c +++ b/lib/libc/stdio/remove.c @@ -42,8 +42,7 @@ __FBSDID("$FreeBSD$"); #include int -remove(file) - const char *file; +remove(const char *file) { struct stat sb; diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c index 5081ac96..af5eb3c 100644 --- a/lib/libc/stdio/setbuffer.c +++ b/lib/libc/stdio/setbuffer.c @@ -39,10 +39,7 @@ __FBSDID("$FreeBSD$"); #include void -setbuffer(fp, buf, size) - FILE *fp; - char *buf; - int size; +setbuffer(FILE *fp, char *buf, int size) { (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); @@ -52,8 +49,7 @@ setbuffer(fp, buf, size) * set line buffering */ int -setlinebuf(fp) - FILE *fp; +setlinebuf(FILE *fp) { return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c index b02fa5d..44ee0ab 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -50,10 +50,7 @@ __FBSDID("$FreeBSD$"); * Small standard I/O/seek/close functions. */ int -__sread(cookie, buf, n) - void *cookie; - char *buf; - int n; +__sread(void *cookie, char *buf, int n) { FILE *fp = cookie; @@ -61,10 +58,7 @@ __sread(cookie, buf, n) } int -__swrite(cookie, buf, n) - void *cookie; - char const *buf; - int n; +__swrite(void *cookie, char const *buf, int n) { FILE *fp = cookie; @@ -72,10 +66,7 @@ __swrite(cookie, buf, n) } fpos_t -__sseek(cookie, offset, whence) - void *cookie; - fpos_t offset; - int whence; +__sseek(void *cookie, fpos_t offset, int whence) { FILE *fp = cookie; @@ -83,8 +74,7 @@ __sseek(cookie, offset, whence) } int -__sclose(cookie) - void *cookie; +__sclose(void *cookie) { return (_close(((FILE *)cookie)->_file)); @@ -94,10 +84,7 @@ __sclose(cookie) * Higher level wrappers. */ int -_sread(fp, buf, n) - FILE *fp; - char *buf; - int n; +_sread(FILE *fp, char *buf, int n) { int ret; @@ -115,10 +102,7 @@ _sread(fp, buf, n) } int -_swrite(fp, buf, n) - FILE *fp; - char const *buf; - int n; +_swrite(FILE *fp, char const *buf, int n) { int ret; int serrno; @@ -145,10 +129,7 @@ _swrite(fp, buf, n) } fpos_t -_sseek(fp, offset, whence) - FILE *fp; - fpos_t offset; - int whence; +_sseek(FILE *fp, fpos_t offset, int whence) { fpos_t ret; int serrno, errret; diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c index 6dd1d69..e15746f 100644 --- a/lib/libc/stdio/tempnam.c +++ b/lib/libc/stdio/tempnam.c @@ -47,8 +47,7 @@ __warn_references(tempnam, extern char *_mktemp(char *); char * -tempnam(dir, pfx) - const char *dir, *pfx; +tempnam(const char *dir, const char *pfx) { int sverrno; char *f, *name; diff --git a/lib/libc/stdio/tmpnam.c b/lib/libc/stdio/tmpnam.c index d395665..ce32dcc 100644 --- a/lib/libc/stdio/tmpnam.c +++ b/lib/libc/stdio/tmpnam.c @@ -47,8 +47,7 @@ __warn_references(tmpnam, extern char *_mktemp(char *); char * -tmpnam(s) - char *s; +tmpnam(char *s) { static u_long tmpcount; static char buf[L_tmpnam]; diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c index f952c01..8729c9c 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -49,10 +49,7 @@ __FBSDID("$FreeBSD$"); #include "xlocale_private.h" int -vscanf_l(locale, fmt, ap) - locale_t locale; - const char * __restrict fmt; - __va_list ap; +vscanf_l(locale_t locale, const char * __restrict fmt, __va_list ap) { int retval; FIX_LOCALE(locale); @@ -63,9 +60,7 @@ vscanf_l(locale, fmt, ap) return (retval); } int -vscanf(fmt, ap) - const char * __restrict fmt; - __va_list ap; +vscanf(const char * __restrict fmt, __va_list ap) { return vscanf_l(__get_locale(), fmt, ap); } diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c index 1cdc59a..3f697e2 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -47,9 +47,7 @@ __FBSDID("$FreeBSD$"); * Non-MT-safe */ int -__swbuf(c, fp) - int c; - FILE *fp; +__swbuf(int c, FILE *fp) { int n; diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c index 341813a..70f8247 100644 --- a/lib/libc/stdio/wsetup.c +++ b/lib/libc/stdio/wsetup.c @@ -47,8 +47,7 @@ __FBSDID("$FreeBSD$"); * _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno. */ int -__swsetup(fp) - FILE *fp; +__swsetup(FILE *fp) { /* make sure stdio is set up */ if (!__sdidinit) -- cgit v1.1