Convert to ANSI C

This commit is contained in:
Todd C. Miller
2010-02-27 09:23:25 -05:00
parent 9e5ff964ad
commit 488c1531eb
22 changed files with 86 additions and 262 deletions

View File

@@ -19,7 +19,7 @@
*/
static struct cclass {
const char *name;
int (*isctype) __P((int));
int (*isctype)(int);
} cclasses[] = {
{ "alnum", isalnum },
{ "alpha", isalpha },

View File

@@ -60,8 +60,7 @@
* This is the expensive (ballback) method.
*/
void
closefrom_fallback(lowfd)
int lowfd;
closefrom_fallback(int lowfd)
{
long fd, maxfd;
@@ -88,8 +87,7 @@ closefrom_fallback(lowfd)
*/
#ifdef HAVE_FCNTL_CLOSEM
void
closefrom(lowfd)
int lowfd;
closefrom(int lowfd)
{
if (fcntl(lowfd, F_CLOSEM, 0) == -1)
closefrom_fallback(lowfd);
@@ -97,8 +95,7 @@ closefrom(lowfd)
#else
# ifdef HAVE_DIRFD
void
closefrom(lowfd)
int lowfd;
closefrom(int lowfd)
{
struct dirent *dent;
DIR *dirp;

View File

@@ -63,13 +63,11 @@
__unused static const char rcsid[] = "$OpenBSD: fnmatch.c,v 1.6 1998/03/19 00:29:59 millert Exp $";
#endif /* LIBC_SCCS and not lint */
static int rangematch __P((const char *, int, int, char **));
static int classmatch __P((const char *, int, int, const char **));
static int rangematch(const char *, int, int, char **);
static int classmatch(const char *, int, int, const char **);
int
fnmatch(pattern, string, flags)
const char *pattern, *string;
int flags;
fnmatch(const char *pattern, const char *string, int flags)
{
const char *stringstart;
char *newp;
@@ -169,15 +167,7 @@ fnmatch(pattern, string, flags)
}
static int
#ifdef __STDC__
rangematch(const char *pattern, int test, int flags, char **newp)
#else
rangematch(pattern, test, flags, newp)
const char *pattern;
int test;
int flags;
char **newp;
#endif
{
int negate, ok, rv;
char c, c2;
@@ -242,15 +232,7 @@ rangematch(pattern, test, flags, newp)
}
static int
#ifdef __STDC__
classmatch(const char *pattern, int test, int foldcase, const char **ep)
#else
classmatch(pattern, test, foldcase, ep)
const char *pattern;
int test;
int foldcase;
const char **ep;
#endif
{
struct cclass *cc;
const char *colon;

View File

@@ -41,6 +41,6 @@
#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
int fnmatch __P((const char *, const char *, int));
int fnmatch(const char *, const char *, int);
#endif /* !_FNMATCH_H_ */

View File

@@ -79,9 +79,7 @@
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
char *
getcwd(pt, size)
char *pt;
size_t size;
getcwd(char *pt, size_t size)
{
struct dirent *dp;
DIR *dir = NULL;

View File

@@ -45,10 +45,7 @@
#ifdef HAVE_FGETLN
ssize_t
getline(bufp, bufsizep, fp)
char **bufp;
size_t *bufsizep;
FILE *fp;
getline(char **bufp, size_t *bufsizep, FILE *fp)
{
char *buf;
size_t bufsize;
@@ -69,10 +66,7 @@ getline(bufp, bufsizep, fp)
}
#else
ssize_t
getline(bufp, bufsizep, fp)
char **bufp;
size_t *bufsizep;
FILE *fp;
getline(char **bufp, size_t *bufsizep, FILE *fp)
{
char *buf;
size_t bufsize;

View File

@@ -25,7 +25,7 @@
#include <compat.h>
const char *
getprogname()
getprogname(void)
{
static const char *progname;
extern int Argc;

View File

@@ -151,34 +151,32 @@ typedef char Char;
#define ismeta(c) (((c)&M_QUOTE) != 0)
static int compare __P((const void *, const void *));
static int g_Ctoc __P((const Char *, char *, unsigned int));
static int g_lstat __P((Char *, struct stat *, glob_t *));
static DIR *g_opendir __P((Char *, glob_t *));
static Char *g_strchr __P((const Char *, int));
static int g_strncmp __P((const Char *, const char *, size_t));
static int g_stat __P((Char *, struct stat *, glob_t *));
static int glob0 __P((const Char *, glob_t *));
static int glob1 __P((Char *, Char *, glob_t *));
static int glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *,
glob_t *));
static int glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *,
Char *, Char *, glob_t *));
static int globextend __P((const Char *, glob_t *));
static int compare(const void *, const void *);
static int g_Ctoc(const Char *, char *, unsigned int);
static int g_lstat(Char *, struct stat *, glob_t *);
static DIR *g_opendir(Char *, glob_t *);
static Char *g_strchr(const Char *, int);
static int g_strncmp(const Char *, const char *, size_t);
static int g_stat(Char *, struct stat *, glob_t *);
static int glob0(const Char *, glob_t *);
static int glob1(Char *, Char *, glob_t *);
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
glob_t *);
static int glob3(Char *, Char *, Char *, Char *, Char *, Char *,
Char *, Char *, glob_t *);
static int globextend(const Char *, glob_t *);
static const Char *
globtilde __P((const Char *, Char *, size_t, glob_t *));
static int globexp1 __P((const Char *, glob_t *));
static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
static int match __P((Char *, Char *, Char *));
globtilde(const Char *, Char *, size_t, glob_t *);
static int globexp1(const Char *, glob_t *);
static int globexp2(const Char *, const Char *, glob_t *, int *);
static int match(Char *, Char *, Char *);
#ifdef DEBUG
static void qprintf __P((const char *, Char *));
static void qprintf(const char *, Char *);
#endif
int
glob(pattern, flags, errfunc, pglob)
const char *pattern;
int flags, (*errfunc) __P((const char *, int));
glob_t *pglob;
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
glob_t *pglob)
{
const unsigned char *patnext;
int c;
@@ -226,9 +224,7 @@ glob(pattern, flags, errfunc, pglob)
* characters
*/
static int
globexp1(pattern, pglob)
const Char *pattern;
glob_t *pglob;
globexp1(const Char *pattern, glob_t *pglob)
{
const Char* ptr = pattern;
int rv;
@@ -251,10 +247,7 @@ globexp1(pattern, pglob)
* If it fails then it tries to glob the rest of the pattern and returns.
*/
static int
globexp2(ptr, pattern, pglob, rv)
const Char *ptr, *pattern;
glob_t *pglob;
int *rv;
globexp2(const Char *ptr, *pattern, glob_t *pglob, int *rv)
{
int i;
Char *lm, *ls;
@@ -359,11 +352,7 @@ globexp2(ptr, pattern, pglob, rv)
* expand tilde from the passwd file.
*/
static const Char *
globtilde(pattern, patbuf, patbuf_len, pglob)
const Char *pattern;
Char *patbuf;
size_t patbuf_len;
glob_t *pglob;
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
{
struct passwd *pwd;
char *h;
@@ -415,10 +404,7 @@ globtilde(pattern, patbuf, patbuf_len, pglob)
}
static int
g_strncmp(s1, s2, n)
const Char *s1;
const char *s2;
size_t n;
g_strncmp(const Char *s1, const char *s2, size_t n)
{
int rv = 0;
@@ -433,9 +419,7 @@ g_strncmp(s1, s2, n)
}
static int
g_charclass(patternp, bufnextp)
const Char **patternp;
Char **bufnextp;
g_charclass(const Char **patternp, Char **bufnextp)
{
const Char *pattern = *patternp + 1;
Char *bufnext = *bufnextp;
@@ -469,9 +453,7 @@ g_charclass(patternp, bufnextp)
* to find no matches.
*/
static int
glob0(pattern, pglob)
const Char *pattern;
glob_t *pglob;
glob0(const Char *pattern, glob_t *pglob)
{
const Char *qpatnext;
int c, err, oldpathc;
@@ -567,16 +549,13 @@ glob0(pattern, pglob)
}
static int
compare(p, q)
const void *p, *q;
compare(const void *p, const void *q)
{
return(strcmp(*(char **)p, *(char **)q));
}
static int
glob1(pattern, pattern_last, pglob)
Char *pattern, *pattern_last;
glob_t *pglob;
glob1(Char *pattern, Char *pattern_last, glob_t *pglob)
{
Char pathbuf[PATH_MAX];
@@ -594,11 +573,8 @@ glob1(pattern, pattern_last, pglob)
* meta characters.
*/
static int
glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, pglob)
Char *pathbuf, *pathbuf_last;
Char *pathend, *pathend_last;
Char *pattern, *pattern_last;
glob_t *pglob;
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Char *pattern, Char *pattern_last, glob_t *pglob)
{
struct stat sb;
Char *p, *q;
@@ -657,11 +633,9 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, pglob
}
static int
glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
restpattern, restpattern_last, pglob)
Char *pathbuf, *pathbuf_last, *pathend, *pathend_last;
Char *pattern, *pattern_last, *restpattern, *restpattern_last;
glob_t *pglob;
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
Char *pattern, Char *pattern_last, Char *restpattern,
Char *restpattern_last, glob_t *pglob)
{
struct dirent *dp;
DIR *dirp;
@@ -734,9 +708,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
*/
static int
globextend(path, pglob)
const Char *path;
glob_t *pglob;
globextend(const Char *path, glob_t *pglob)
{
char **pathv;
int i;
@@ -784,8 +756,7 @@ globextend(path, pglob)
* pattern causes a recursion level.
*/
static int
match(name, pat, patend)
Char *name, *pat, *patend;
match(Char *name, Char *pat, Char *patend)
{
int ok, negate_range;
Char c, k;
@@ -840,8 +811,7 @@ match(name, pat, patend)
/* Free allocated data belonging to a glob_t structure. */
void
globfree(pglob)
glob_t *pglob;
globfree(glob_t *pglob)
{
int i;
char **pp;
@@ -857,9 +827,7 @@ globfree(pglob)
}
static DIR *
g_opendir(str, pglob)
Char *str;
glob_t *pglob;
g_opendir(Char *str, glob_t *pglob)
{
char buf[PATH_MAX];
@@ -874,10 +842,7 @@ g_opendir(str, pglob)
}
static int
g_lstat(fn, sb, pglob)
Char *fn;
struct stat *sb;
glob_t *pglob;
g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
{
char buf[PATH_MAX];
@@ -887,10 +852,7 @@ g_lstat(fn, sb, pglob)
}
static int
g_stat(fn, sb, pglob)
Char *fn;
struct stat *sb;
glob_t *pglob;
g_stat(Char *fn, struct stat *sb, glob_t *pglob)
{
char buf[PATH_MAX];
@@ -900,9 +862,7 @@ g_stat(fn, sb, pglob)
}
static Char *
g_strchr(str, ch)
const Char *str;
int ch;
g_strchr(const Char *str, int ch)
{
do {
if (*str == ch)
@@ -912,10 +872,7 @@ g_strchr(str, ch)
}
static int
g_Ctoc(str, buf, len)
const Char *str;
char *buf;
unsigned int len;
g_Ctoc(const Char *str, char *buf, unsigned int len)
{
while (len--) {
@@ -927,9 +884,7 @@ g_Ctoc(str, buf, len)
#ifdef DEBUG
static void
qprintf(str, s)
const char *str;
Char *s;
qprintf(const char *str, Char *s)
{
Char *p;

View File

@@ -45,11 +45,7 @@ typedef struct {
int gl_flags; /* Copy of flags parameter to glob. */
char **gl_pathv; /* List of paths matching pattern. */
/* Copy of errfunc parameter to glob. */
#ifdef __STDC__
int (*gl_errfunc)(const char *, int);
#else
int (*gl_errfunc)();
#endif
} glob_t;
/* Flags */
@@ -73,12 +69,7 @@ typedef struct {
#define GLOB_NOSYS (-4) /* Function not supported. */
#define GLOB_ABEND GLOB_ABORTED
#ifdef __STDC__
int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);
#else
int glob();
void globfree();
#endif
#endif /* !_GLOB_H_ */

View File

@@ -19,8 +19,7 @@
#undef isblank
int
isblank(ch)
int ch;
isblank(int ch)
{
return(ch == ' ' || ch == '\t');
}

View File

@@ -26,10 +26,7 @@
* Find the last occurrence of 'c' in the buffer 's' of size 'n'.
*/
void *
memrchr(s, c, n)
const void *s;
int c;
size_t n;
memrchr(const void *s, int c, size_t n)
{
const unsigned char *cp;

View File

@@ -31,12 +31,11 @@
#include <compat.h>
static unsigned int get_random __P((void));
static void seed_random __P((void));
static unsigned int get_random(void);
static void seed_random(void);
int
mkstemp(path)
char *path;
mkstemp(char *path)
{
char *start, *cp;
int fd, r;
@@ -84,7 +83,7 @@ mkstemp(path)
#endif
static void
seed_random()
seed_random(void)
{
SEED_T seed;
struct timespec ts;
@@ -99,7 +98,7 @@ seed_random()
}
static unsigned int
get_random()
get_random(void)
{
static int initialized;

View File

@@ -32,9 +32,7 @@
#include "compat.h"
int
nanosleep(ts, rts)
const struct timespec *ts;
struct timespec *rts;
nanosleep(const struct timespec *ts, struct timespec *rts)
{
struct timeval timeout, endtime, now;
int rval;

View File

@@ -24,10 +24,7 @@
#include <compat.h>
int
sigaction(signo, sa, osa)
int signo;
const sigaction_t *sa;
sigaction_t *osa;
sigaction(int signo, const sigaction_t *sa, sigaction_t *osa)
{
sigaction_t nsa;
int error;
@@ -47,8 +44,7 @@ sigaction(signo, sa, osa)
}
int
sigemptyset(set)
sigset_t *set;
sigemptyset(sigset_t *set)
{
*set = 0;
@@ -56,8 +52,7 @@ sigemptyset(set)
}
int
sigfillset(set)
sigset_t *set;
sigfillset(sigset_t *set)
{
*set = ~0;;
@@ -65,9 +60,7 @@ sigfillset(set)
}
int
sigaddset(set, signo)
sigset_t *set;
int signo;
sigaddset(sigset_t *set, int signo)
{
if (signo <= 0 || signo >= NSIG) {
@@ -80,9 +73,7 @@ sigaddset(set, signo)
}
int
sigdelset(set, signo)
sigset_t *set;
int signo;
sigdelset(sigset_t *set, int signo)
{
if (signo <= 0 || signo >= NSIG) {
@@ -95,19 +86,14 @@ sigdelset(set, signo)
}
int
sigismember(set, signo)
sigset_t *set;
int signo;
sigismember(sigset_t *set, int signo)
{
return(ISSET(*set, sigmask(signo)));
}
int
sigprocmask(how, set, oset)
int how;
const sigset_t *set;
sigset_t *oset;
sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
int mask;

View File

@@ -69,16 +69,11 @@
# include <malloc.h>
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <limits.h>
#ifdef __STDC__
#include <stdarg.h>
#else
# include <varargs.h>
#endif
#include <compat.h>
static int xxxprintf __P((char **, size_t, int, const char *, va_list));
static int xxxprintf(char **, size_t, int, const char *, va_list);
/*
* Some systems may not have these defined in <limits.h>
@@ -129,10 +124,7 @@ static int xxxprintf __P((char **, size_t, int, const char *, va_list));
#ifndef HAVE_MEMCHR
void *
memchr(s, c, n)
const void *s;
unsigned char c;
size_t n;
memchr(const void *s, unsigned char c, size_t n)
{
if (n != 0) {
const unsigned char *p = s;
@@ -153,11 +145,7 @@ memchr(s, c, n)
* use the given digits.
*/
static char *
__ultoa(val, endp, base, octzero, xdigs)
unsigned long val;
char *endp;
int base, octzero;
char *xdigs;
__ultoa(unsigned long val, char *endp, int base, int octzero, char *xdigs)
{
char *cp = endp;
long sval;
@@ -217,11 +205,7 @@ __ultoa(val, endp, base, octzero, xdigs)
# define __uqtoa(v, e, b, o, x) __ultoa((unsigned long)(v), (e), (b), (o), (x))
# else
static char *
__uqtoa(val, endp, base, octzero, xdigs)
unsigned long long val;
char *endp;
int base, octzero;
char *xdigs;
__uqtoa(unsigned long long val, char *endp, int base, int octzero, char *xdigs)
{
char *cp = endp;
long long sval;
@@ -275,12 +259,7 @@ __uqtoa(val, endp, base, octzero, xdigs)
* Actual printf innards.
*/
static int
xxxprintf(strp, strsize, alloc, fmt0, ap)
char **strp;
size_t strsize;
int alloc;
const char *fmt0;
va_list ap;
xxxprintf(char **strp, size_t strsize, int alloc, const char *fmt0, va_list ap)
{
char *fmt; /* format string */
int ch; /* character from fmt */
@@ -699,11 +678,7 @@ done:
#ifndef HAVE_VSNPRINTF
int
vsnprintf(str, n, fmt, ap)
char *str;
size_t n;
const char *fmt;
va_list ap;
vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
{
return (xxxprintf(&str, n, 0, fmt, ap));
@@ -712,24 +687,12 @@ vsnprintf(str, n, fmt, ap)
#ifndef HAVE_SNPRINTF
int
#ifdef __STDC__
snprintf(char *str, size_t n, char const *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
char *str;
size_t n;
char const *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
ret = xxxprintf(&str, n, 0, fmt, ap);
va_end(ap);
return (ret);
@@ -738,10 +701,7 @@ snprintf(str, n, fmt, va_alist)
#ifndef HAVE_VASPRINTF
int
vasprintf(str, fmt, ap)
char **str;
const char *fmt;
va_list ap;
vasprintf(char **str, const char *fmt, va_list ap)
{
return (xxxprintf(str, 0, 1, fmt, ap));
@@ -750,23 +710,12 @@ vasprintf(str, fmt, ap)
#ifndef HAVE_ASPRINTF
int
#ifdef __STDC__
asprintf(char **str, char const *fmt, ...)
#else
asprintf(str, fmt, va_alist)
char **str;
char const *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
ret = xxxprintf(str, 0, 1, fmt, ap);
va_end(ap);
return (ret);

View File

@@ -59,9 +59,7 @@ static const char ichars[256] = {
};
int
strcasecmp(s1, s2)
const char *s1;
const char *s2;
strcasecmp(const char *s1, const char *s2)
{
const unsigned char *us1 = (const unsigned char *) s1;
const unsigned char *us2 = (const unsigned char *) s2;
@@ -74,10 +72,7 @@ strcasecmp(s1, s2)
}
int
strncasecmp(s1, s2, n)
const char *s1;
const char *s2;
size_t n;
strncasecmp(const char *s1, const char *s2, size_t n)
{
const unsigned char *us1 = (const unsigned char *) s1;
const unsigned char *us2 = (const unsigned char *) s2;

View File

@@ -28,8 +28,7 @@
* Map errno -> error string.
*/
char *
strerror(n)
int n;
strerror(int n)
{
extern int sys_nerr;
extern char *sys_errlist[];

View File

@@ -31,10 +31,7 @@
* If retval >= siz, truncation occurred.
*/
size_t
strlcat(dst, src, siz)
char *dst;
const char *src;
size_t siz;
strlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;

View File

@@ -27,10 +27,7 @@
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(dst, src, siz)
char *dst;
const char *src;
size_t siz;
strlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;

View File

@@ -24,8 +24,7 @@
* Get signal description string
*/
char *
strsignal(signo)
int signo;
strsignal(int signo)
{
extern const char *const sys_siglist[];

View File

@@ -22,10 +22,6 @@ struct utimbuf {
time_t modtime; /* mod time */
};
#ifdef __STDC__
int utime(const char *, const struct utimbuf *);
#else
int utime();
#endif
#endif /* _UTIME_H */

View File

@@ -36,9 +36,7 @@
* Emulate utimes() via utime()
*/
int
utimes(file, times)
const char *file;
const struct timeval *times;
utimes(const char *file, const struct timeval *times)
{
if (times != NULL) {
struct utimbuf utb;
@@ -56,9 +54,7 @@ utimes(file, times)
* Emulate futimes() via futime()
*/
int
futimes(fd, times)
int fd;
const struct timeval *times;
futimes(int fd, const struct timeval *times)
{
if (times != NULL) {
struct utimbuf utb;