Convert libc/stdio from K&R to ANSI C

And add '__restrict' where it appeared in the header prototypes
This commit is contained in:
Ed Maste 2013-04-23 14:36:44 +00:00
parent 5628dd0893
commit 5a6307cf42
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249810
34 changed files with 53 additions and 151 deletions

View File

@ -45,8 +45,7 @@ __FBSDID("$FreeBSD$");
#undef clearerr_unlocked
void
clearerr(fp)
FILE *fp;
clearerr(FILE *fp)
{
FLOCKFILE(fp);
__sclearerr(fp);

View File

@ -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;

View File

@ -43,8 +43,7 @@ __FBSDID("$FreeBSD$");
#include "local.h"
int
fgetc(fp)
FILE *fp;
fgetc(FILE *fp)
{
int retval;
FLOCKFILE(fp);

View File

@ -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;

View File

@ -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 };

View File

@ -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;

View File

@ -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;

View File

@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$");
* given FILE's buffer empty.
*/
int
fpurge(fp)
FILE *fp;
fpurge(FILE *fp)
{
int retval;
FLOCKFILE(fp);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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));
}

View File

@ -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;

View File

@ -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;

View File

@ -42,8 +42,7 @@ __FBSDID("$FreeBSD$");
#include "glue.h"
int
_fwalk(function)
int (*function)(FILE *);
_fwalk(int (*function)(FILE *))
{
FILE *fp;
int n, ret;

View File

@ -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;

View File

@ -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;

View File

@ -39,8 +39,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
int
getw(fp)
FILE *fp;
getw(FILE *fp)
{
int x;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -42,8 +42,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
int
remove(file)
const char *file;
remove(const char *file)
{
struct stat sb;

View File

@ -39,10 +39,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
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));

View File

@ -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;

View File

@ -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;

View File

@ -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];

View File

@ -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);
}

View File

@ -47,9 +47,7 @@ __FBSDID("$FreeBSD$");
* Non-MT-safe
*/
int
__swbuf(c, fp)
int c;
FILE *fp;
__swbuf(int c, FILE *fp)
{
int n;

View File

@ -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)