Convert to ANSI C

This commit is contained in:
Todd C. Miller
2010-03-04 20:18:22 -05:00
parent 6470a057e1
commit c857c74e3a
14 changed files with 55 additions and 117 deletions

View File

@@ -28,7 +28,6 @@ compat = $(top_srcdir)/compat
# Compiler & tools to use # Compiler & tools to use
CC = @CC@ CC = @CC@
NROFF = nroff -Tascii
# Our install program supports extra flags... # Our install program supports extra flags...
INSTALL = $(SHELL) $(top_srcdir)/install-sh -c INSTALL = $(SHELL) $(top_srcdir)/install-sh -c

View File

@@ -63,10 +63,7 @@ static struct aix_limit aix_limits[] = {
}; };
static int static int
aix_getlimit(user, lim, valp) aix_getlimit(char *user, char *lim, rlim64_t *valp)
char *user;
char *lim;
rlim64_t *valp;
{ {
int val; int val;
@@ -79,8 +76,7 @@ aix_getlimit(user, lim, valp)
} }
void void
aix_setlimits(user) aix_setlimits(char *user)
char *user;
{ {
struct rlimit64 rlim; struct rlimit64 rlim;
rlim64_t val; rlim64_t val;

View File

@@ -46,7 +46,9 @@
# include <inttypes.h> # include <inttypes.h>
#endif #endif
#include "sudo.h" #include "compat.h"
#include "alloc.h"
#include "error.h"
/* /*
* If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
@@ -67,8 +69,7 @@
* malloc(3) fails. * malloc(3) fails.
*/ */
void * void *
emalloc(size) emalloc(size_t size)
size_t size;
{ {
void *ptr; void *ptr;
@@ -85,9 +86,7 @@ emalloc(size)
* if overflow would occur or if the system malloc(3) fails. * if overflow would occur or if the system malloc(3) fails.
*/ */
void * void *
emalloc2(nmemb, size) emalloc2(size_t nmemb, size_t size)
size_t nmemb;
size_t size;
{ {
void *ptr; void *ptr;
@@ -108,9 +107,7 @@ emalloc2(nmemb, size)
* if the system realloc(3) does not support this. * if the system realloc(3) does not support this.
*/ */
void * void *
erealloc(ptr, size) erealloc(void *ptr, size_t size)
void *ptr;
size_t size;
{ {
if (size == 0) if (size == 0)
@@ -129,10 +126,7 @@ erealloc(ptr, size)
* does not support this. * does not support this.
*/ */
void * void *
erealloc3(ptr, nmemb, size) erealloc3(void *ptr, size_t nmemb, size_t size)
void *ptr;
size_t nmemb;
size_t size;
{ {
if (nmemb == 0 || size == 0) if (nmemb == 0 || size == 0)
@@ -152,8 +146,7 @@ erealloc3(ptr, nmemb, size)
* malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal. * malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal.
*/ */
char * char *
estrdup(src) estrdup(const char *src)
const char *src;
{ {
char *dst = NULL; char *dst = NULL;
size_t len; size_t len;
@@ -172,9 +165,7 @@ estrdup(src)
* malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal. * malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal.
*/ */
char * char *
estrndup(src, maxlen) estrndup(const char *src, size_t maxlen)
const char *src;
size_t maxlen;
{ {
char *dst = NULL; char *dst = NULL;
size_t len; size_t len;
@@ -213,10 +204,7 @@ easprintf(char **ret, const char *fmt, ...)
* returns -1 (out of memory). * returns -1 (out of memory).
*/ */
int int
evasprintf(ret, format, args) evasprintf(char **ret, const char *format, va_list args)
char **ret;
const char *format;
va_list args;
{ {
int len; int len;
@@ -229,8 +217,7 @@ evasprintf(ret, format, args)
* Wrapper for free(3) so we can depend on C89 semantics. * Wrapper for free(3) so we can depend on C89 semantics.
*/ */
void void
efree(ptr) efree(void *ptr)
void *ptr;
{ {
if (ptr != NULL) if (ptr != NULL)
free(ptr); free(ptr);

View File

@@ -39,14 +39,15 @@
# endif # endif
#endif /* HAVE_STRING_H */ #endif /* HAVE_STRING_H */
#include "sudo.h" #include "compat.h"
#include "missing.h"
int int
atobool(const char *str) atobool(const char *str)
{ {
if (strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) if (strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0)
return TRUE; return 1;
if (strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0) if (strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0)
return FALSE; return 0;
return -1; return -1;
} }

View File

@@ -67,10 +67,7 @@ warningx(const char *fmt, ...)
} }
static void static void
_warning(use_errno, fmt, ap) _warning(int use_errno, const char *fmt, va_list ap)
int use_errno;
const char *fmt;
va_list ap;
{ {
int serrno = errno; int serrno = errno;

View File

@@ -47,7 +47,7 @@
# include <emul/timespec.h> # include <emul/timespec.h>
#endif #endif
#include "sudo.h" #include "sudo.h" /* XXX - for SUDO_LOCK and friends */
#ifndef LINE_MAX #ifndef LINE_MAX
# define LINE_MAX 2048 # define LINE_MAX 2048
@@ -57,10 +57,7 @@
* Update the access and modify times on an fd or file. * Update the access and modify times on an fd or file.
*/ */
int int
touch(fd, path, tsp) touch(int fd, char *path, struct timespec *tsp)
int fd;
char *path;
struct timespec *tsp;
{ {
struct timeval times[2]; struct timeval times[2];
@@ -85,9 +82,7 @@ touch(fd, path, tsp)
*/ */
#ifdef HAVE_LOCKF #ifdef HAVE_LOCKF
int int
lock_file(fd, lockit) lock_file(int fd, int lockit)
int fd;
int lockit;
{ {
int op = 0; int op = 0;
@@ -106,9 +101,7 @@ lock_file(fd, lockit)
} }
#elif HAVE_FLOCK #elif HAVE_FLOCK
int int
lock_file(fd, lockit) lock_file(int fd, int lockit)
int fd;
int lockit;
{ {
int op = 0; int op = 0;
@@ -127,9 +120,7 @@ lock_file(fd, lockit)
} }
#else #else
int int
lock_file(fd, lockit) lock_file(int fd, int lockit)
int fd;
int lockit;
{ {
#ifdef F_SETLK #ifdef F_SETLK
int func; int func;
@@ -154,8 +145,7 @@ lock_file(fd, lockit)
* and trailing spaces. Returns static storage that is reused. * and trailing spaces. Returns static storage that is reused.
*/ */
char * char *
sudo_parseln(fp) sudo_parseln(FILE *fp)
FILE *fp;
{ {
size_t len; size_t len;
char *cp = NULL; char *cp = NULL;

View File

@@ -49,7 +49,9 @@
# endif # endif
#endif #endif
#include "sudo.h" #include "compat.h"
#include "alloc.h"
#include "error.h"
#include "missing.h" #include "missing.h"
#include "lbuf.h" #include "lbuf.h"
@@ -60,7 +62,7 @@
#endif #endif
int int
get_ttycols() get_ttycols(void)
{ {
char *p; char *p;
int cols; int cols;
@@ -82,11 +84,7 @@ get_ttycols()
*/ */
void void
lbuf_init(lbuf, buf, indent, continuation) lbuf_init(struct lbuf *lbuf, char *buf, int indent, int continuation)
struct lbuf *lbuf;
char *buf;
int indent;
int continuation;
{ {
lbuf->continuation = continuation; lbuf->continuation = continuation;
lbuf->indent = indent; lbuf->indent = indent;
@@ -96,8 +94,7 @@ lbuf_init(lbuf, buf, indent, continuation)
} }
void void
lbuf_destroy(lbuf) lbuf_destroy(struct lbuf *lbuf)
struct lbuf *lbuf;
{ {
efree(lbuf->buf); efree(lbuf->buf);
lbuf->buf = NULL; lbuf->buf = NULL;
@@ -189,8 +186,7 @@ lbuf_append(struct lbuf *lbuf, ...)
* The lbuf is reset on return. * The lbuf is reset on return.
*/ */
void void
lbuf_print(lbuf) lbuf_print(struct lbuf *lbuf)
struct lbuf *lbuf;
{ {
char *cp; char *cp;
int i, have, contlen; int i, have, contlen;

View File

@@ -29,7 +29,11 @@
# endif # endif
#endif /* STDC_HEADERS */ #endif /* STDC_HEADERS */
#include "sudo.h" #include "compat.h"
#include "list.h"
#ifdef DEBUG
# include "error.h"
#endif
struct list_proto { struct list_proto {
struct list_proto *prev; struct list_proto *prev;
@@ -46,8 +50,7 @@ struct list_head_proto {
* Returns the popped element. * Returns the popped element.
*/ */
void * void *
tq_pop(vh) tq_pop(void *vh)
void *vh;
{ {
struct list_head_proto *h = (struct list_head_proto *)vh; struct list_head_proto *h = (struct list_head_proto *)vh;
void *last = NULL; void *last = NULL;
@@ -70,9 +73,7 @@ tq_pop(vh)
* with a head node. * with a head node.
*/ */
void void
list2tq(vh, vl) list2tq(void *vh, void *vl)
void *vh;
void *vl;
{ {
struct list_head_proto *h = (struct list_head_proto *)vh; struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl; struct list_proto *l = (struct list_proto *)vl;
@@ -98,9 +99,7 @@ list2tq(vh, vl)
* circular properties of the prev pointer to simplify the logic. * circular properties of the prev pointer to simplify the logic.
*/ */
void void
list_append(vl1, vl2) list_append(void *vl1, void *vl2)
void *vl1;
void *vl2;
{ {
struct list_proto *l1 = (struct list_proto *)vl1; struct list_proto *l1 = (struct list_proto *)vl1;
struct list_proto *l2 = (struct list_proto *)vl2; struct list_proto *l2 = (struct list_proto *)vl2;
@@ -116,9 +115,7 @@ list_append(vl1, vl2)
* e from a semi-circle queue to normal doubly-linked list. * e from a semi-circle queue to normal doubly-linked list.
*/ */
void void
tq_append(vh, vl) tq_append(void *vh, void *vl)
void *vh;
void *vl;
{ {
struct list_head_proto *h = (struct list_head_proto *)vh; struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl; struct list_proto *l = (struct list_proto *)vl;
@@ -136,9 +133,7 @@ tq_append(vh, vl)
* Remove element from the tail_queue * Remove element from the tail_queue
*/ */
void void
tq_remove(vh, vl) tq_remove(void *vh, void *vl)
void *vh;
void *vl;
{ {
struct list_head_proto *h = (struct list_head_proto *)vh; struct list_head_proto *h = (struct list_head_proto *)vh;
struct list_proto *l = (struct list_proto *)vl; struct list_proto *l = (struct list_proto *)vl;

View File

@@ -94,8 +94,7 @@ get_pty(int *master, int *slave, char *name, size_t namesz, uid_t uid)
#elif defined(HAVE_GRANTPT) #elif defined(HAVE_GRANTPT)
# ifndef HAVE_POSIX_OPENPT # ifndef HAVE_POSIX_OPENPT
static int static int
posix_openpt(oflag) posix_openpt(int oflag)
int oflag;
{ {
int fd; int fd;

View File

@@ -30,7 +30,7 @@
#include "compat.h" #include "compat.h"
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
char *cp, *cmnd; char *cp, *cmnd;

View File

@@ -583,8 +583,7 @@ disable_coredumps(void)
* Cleanup hook for error()/errorx() * Cleanup hook for error()/errorx()
*/ */
void void
cleanup(gotsignal) cleanup(int gotsignal)
int gotsignal;
{ {
#if 0 /* XXX */ #if 0 /* XXX */
struct sudo_nss *nss; struct sudo_nss *nss;

View File

@@ -64,10 +64,7 @@ static char *find_editor();
* Wrapper to allow users to edit privileged files with their own uid. * Wrapper to allow users to edit privileged files with their own uid.
*/ */
int int
sudo_edit(argc, argv, envp) sudo_edit(int argc, char **argv, char **envp)
int argc;
char **argv;
char **envp;
{ {
ssize_t nread, nwritten; ssize_t nread, nwritten;
pid_t kidpid, pid; pid_t kidpid, pid;
@@ -350,7 +347,7 @@ cleanup:
* the uid of the invoking user, not the runas (privileged) user. * the uid of the invoking user, not the runas (privileged) user.
*/ */
static char * static char *
find_editor() find_editor(void)
{ {
char *cp, *editor = NULL, **ev, *ev0[4]; char *cp, *editor = NULL, **ev, *ev0[4];

View File

@@ -105,9 +105,7 @@ int term_erase;
int term_kill; int term_kill;
int int
term_restore(fd, flush) term_restore(int fd, int flush)
int fd;
int flush;
{ {
if (changed) { if (changed) {
int flags = TCSASOFT; int flags = TCSASOFT;
@@ -120,8 +118,7 @@ term_restore(fd, flush)
} }
int int
term_noecho(fd) term_noecho(int fd)
int fd;
{ {
if (!changed && tcgetattr(fd, &oterm) != 0) if (!changed && tcgetattr(fd, &oterm) != 0)
return(0); return(0);
@@ -140,10 +137,7 @@ term_noecho(fd)
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) #if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
int int
term_raw(fd, opost, isig) term_raw(int fd, int opost, int isig)
int fd;
int opost;
int isig;
{ {
struct termios term; struct termios term;
@@ -168,8 +162,7 @@ term_raw(fd, opost, isig)
} }
int int
term_cbreak(fd) term_cbreak(int fd)
int fd;
{ {
if (!changed && tcgetattr(fd, &oterm) != 0) if (!changed && tcgetattr(fd, &oterm) != 0)
return(0); return(0);
@@ -192,10 +185,7 @@ term_cbreak(fd)
} }
int int
term_copy(src, dst, opost) term_copy(int src, int dst, int opost)
int src;
int dst;
int opost;
{ {
struct termios tt; struct termios tt;
@@ -213,9 +203,7 @@ term_copy(src, dst, opost)
#else /* SGTTY */ #else /* SGTTY */
int int
term_raw(fd, onlcr) term_raw(int fd, int onlcr)
int fd;
int onlcr;
{ {
if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0)
return(0); return(0);
@@ -234,8 +222,7 @@ term_raw(fd, onlcr)
} }
int int
term_cbreak(fd) term_cbreak(int fd)
int fd;
{ {
if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0)
return(0); return(0);
@@ -253,10 +240,7 @@ term_cbreak(fd)
} }
int int
term_copy(src, dst, onlcr) term_copy(int src, int dst, int onlcr)
int src;
int dst;
int onlcr;
{ {
struct sgttyb b; struct sgttyb b;
struct tchars tc; struct tchars tc;

View File

@@ -24,9 +24,7 @@
* the compiler will not be able to optimize away this function. * the compiler will not be able to optimize away this function.
*/ */
void void
zero_bytes(v, n) zero_bytes(volatile void *v, size_t n)
volatile void *v;
size_t n;
{ {
volatile char *p, *ep; volatile char *p, *ep;