From 5a6307cf42c5b4965435b3b7af74a37fd4dc17b9 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 23 Apr 2013 14:36:44 +0000 Subject: [PATCH] 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 3683c10c7bd5..f161a6e1e802 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 4252c726270a..2e19b9febcd8 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 0e5e6233f79c..2ee4d7a78cb5 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 ba2a0e646d1a..9abf559bf108 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 e8dd38282adc..be196b73c687 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 95467173dcb0..1878c2f4e134 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 2d85f5357c08..b08e3366ac68 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 844772975e3d..f205bdfc3bf5 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 75fb131e6f1a..3b6101f92f4d 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 650adcd09dbb..3b8f2c9d1b68 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 7d8feca021f7..dc5508d4d25b 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 55ab65760d2b..2897eebf9c88 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 b56fbba48d0e..c6b8b785918d 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 9a1c1601c236..2c8800ccfe19 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 71c83c2cd766..1a28b6a79c01 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 f26ff845b4ae..151837b29025 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 08587c7bf56d..707d362799d0 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 51773180ede9..c7c1c2fa38c8 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 7d75000f739b..ed0313eb60c2 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 42f77cdc0a2b..a92087e0eae7 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 24f9a6795e60..58783ddefa85 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 80f015473aa3..89c079818fb7 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 6b6278641561..aaffece49d76 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 9a17784a055d..756155902f29 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 31d5135a8dbd..5ee7fc1c63f0 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 922f9beeb438..0360cafc4052 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 b2375135db46..2e984baf9360 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 5081ac9653d3..af5eb3cabf6e 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 b02fa5d64b80..44ee0ab41210 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 6dd1d69c164b..e15746f31a4d 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 d395665e7bf2..ce32dcc28149 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 f952c01fec30..8729c9ca6ba8 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 1cdc59abc945..3f697e287a1f 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 341813a18ecb..70f8247c076b 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)