From: Todd C. Miller Date: Fri, 5 Mar 2010 01:18:22 +0000 (-0500) Subject: Convert to ANSI C X-Git-Tag: SUDO_1_8_0~850 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c857c74e3ada48e8c1a60c242ae8c3e50ce890d2;p=sudo Convert to ANSI C --- diff --git a/src/Makefile.in b/src/Makefile.in index 2feec155f..2fb34dd3c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -28,7 +28,6 @@ compat = $(top_srcdir)/compat # Compiler & tools to use CC = @CC@ -NROFF = nroff -Tascii # Our install program supports extra flags... INSTALL = $(SHELL) $(top_srcdir)/install-sh -c diff --git a/src/aix.c b/src/aix.c index aa6156819..f7ea50a8c 100644 --- a/src/aix.c +++ b/src/aix.c @@ -63,10 +63,7 @@ static struct aix_limit aix_limits[] = { }; static int -aix_getlimit(user, lim, valp) - char *user; - char *lim; - rlim64_t *valp; +aix_getlimit(char *user, char *lim, rlim64_t *valp) { int val; @@ -79,8 +76,7 @@ aix_getlimit(user, lim, valp) } void -aix_setlimits(user) - char *user; +aix_setlimits(char *user) { struct rlimit64 rlim; rlim64_t val; diff --git a/src/alloc.c b/src/alloc.c index 465b24d9f..0811ef71e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -46,7 +46,9 @@ # include #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 @@ -67,8 +69,7 @@ * malloc(3) fails. */ void * -emalloc(size) - size_t size; +emalloc(size_t size) { void *ptr; @@ -85,9 +86,7 @@ emalloc(size) * if overflow would occur or if the system malloc(3) fails. */ void * -emalloc2(nmemb, size) - size_t nmemb; - size_t size; +emalloc2(size_t nmemb, size_t size) { void *ptr; @@ -108,9 +107,7 @@ emalloc2(nmemb, size) * if the system realloc(3) does not support this. */ void * -erealloc(ptr, size) - void *ptr; - size_t size; +erealloc(void *ptr, size_t size) { if (size == 0) @@ -129,10 +126,7 @@ erealloc(ptr, size) * does not support this. */ void * -erealloc3(ptr, nmemb, size) - void *ptr; - size_t nmemb; - size_t size; +erealloc3(void *ptr, size_t nmemb, size_t size) { if (nmemb == 0 || size == 0) @@ -152,8 +146,7 @@ erealloc3(ptr, nmemb, size) * malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal. */ char * -estrdup(src) - const char *src; +estrdup(const char *src) { char *dst = NULL; size_t len; @@ -172,9 +165,7 @@ estrdup(src) * malloc(3) fails. NOTE: unlike strdup(3), estrdup(NULL) is legal. */ char * -estrndup(src, maxlen) - const char *src; - size_t maxlen; +estrndup(const char *src, size_t maxlen) { char *dst = NULL; size_t len; @@ -213,10 +204,7 @@ easprintf(char **ret, const char *fmt, ...) * returns -1 (out of memory). */ int -evasprintf(ret, format, args) - char **ret; - const char *format; - va_list args; +evasprintf(char **ret, const char *format, va_list args) { int len; @@ -229,8 +217,7 @@ evasprintf(ret, format, args) * Wrapper for free(3) so we can depend on C89 semantics. */ void -efree(ptr) - void *ptr; +efree(void *ptr) { if (ptr != NULL) free(ptr); diff --git a/src/atobool.c b/src/atobool.c index d8d637a1a..9f02ebe0d 100644 --- a/src/atobool.c +++ b/src/atobool.c @@ -39,14 +39,15 @@ # endif #endif /* HAVE_STRING_H */ -#include "sudo.h" +#include "compat.h" +#include "missing.h" int atobool(const char *str) { if (strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) - return TRUE; + return 1; if (strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0) - return FALSE; + return 0; return -1; } diff --git a/src/error.c b/src/error.c index 0f33cde49..e6963af0a 100644 --- a/src/error.c +++ b/src/error.c @@ -67,10 +67,7 @@ warningx(const char *fmt, ...) } static void -_warning(use_errno, fmt, ap) - int use_errno; - const char *fmt; - va_list ap; +_warning(int use_errno, const char *fmt, va_list ap) { int serrno = errno; diff --git a/src/fileops.c b/src/fileops.c index 5e9d31dd6..af942c511 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -47,7 +47,7 @@ # include #endif -#include "sudo.h" +#include "sudo.h" /* XXX - for SUDO_LOCK and friends */ #ifndef LINE_MAX # define LINE_MAX 2048 @@ -57,10 +57,7 @@ * Update the access and modify times on an fd or file. */ int -touch(fd, path, tsp) - int fd; - char *path; - struct timespec *tsp; +touch(int fd, char *path, struct timespec *tsp) { struct timeval times[2]; @@ -85,9 +82,7 @@ touch(fd, path, tsp) */ #ifdef HAVE_LOCKF int -lock_file(fd, lockit) - int fd; - int lockit; +lock_file(int fd, int lockit) { int op = 0; @@ -106,9 +101,7 @@ lock_file(fd, lockit) } #elif HAVE_FLOCK int -lock_file(fd, lockit) - int fd; - int lockit; +lock_file(int fd, int lockit) { int op = 0; @@ -127,9 +120,7 @@ lock_file(fd, lockit) } #else int -lock_file(fd, lockit) - int fd; - int lockit; +lock_file(int fd, int lockit) { #ifdef F_SETLK int func; @@ -154,8 +145,7 @@ lock_file(fd, lockit) * and trailing spaces. Returns static storage that is reused. */ char * -sudo_parseln(fp) - FILE *fp; +sudo_parseln(FILE *fp) { size_t len; char *cp = NULL; diff --git a/src/lbuf.c b/src/lbuf.c index b9ef3eaff..d63433230 100644 --- a/src/lbuf.c +++ b/src/lbuf.c @@ -49,7 +49,9 @@ # endif #endif -#include "sudo.h" +#include "compat.h" +#include "alloc.h" +#include "error.h" #include "missing.h" #include "lbuf.h" @@ -60,7 +62,7 @@ #endif int -get_ttycols() +get_ttycols(void) { char *p; int cols; @@ -82,11 +84,7 @@ get_ttycols() */ void -lbuf_init(lbuf, buf, indent, continuation) - struct lbuf *lbuf; - char *buf; - int indent; - int continuation; +lbuf_init(struct lbuf *lbuf, char *buf, int indent, int continuation) { lbuf->continuation = continuation; lbuf->indent = indent; @@ -96,8 +94,7 @@ lbuf_init(lbuf, buf, indent, continuation) } void -lbuf_destroy(lbuf) - struct lbuf *lbuf; +lbuf_destroy(struct lbuf *lbuf) { efree(lbuf->buf); lbuf->buf = NULL; @@ -189,8 +186,7 @@ lbuf_append(struct lbuf *lbuf, ...) * The lbuf is reset on return. */ void -lbuf_print(lbuf) - struct lbuf *lbuf; +lbuf_print(struct lbuf *lbuf) { char *cp; int i, have, contlen; diff --git a/src/list.c b/src/list.c index 1d8c2012b..3d35ed48f 100644 --- a/src/list.c +++ b/src/list.c @@ -29,7 +29,11 @@ # endif #endif /* STDC_HEADERS */ -#include "sudo.h" +#include "compat.h" +#include "list.h" +#ifdef DEBUG +# include "error.h" +#endif struct list_proto { struct list_proto *prev; @@ -46,8 +50,7 @@ struct list_head_proto { * Returns the popped element. */ void * -tq_pop(vh) - void *vh; +tq_pop(void *vh) { struct list_head_proto *h = (struct list_head_proto *)vh; void *last = NULL; @@ -70,9 +73,7 @@ tq_pop(vh) * with a head node. */ void -list2tq(vh, vl) - void *vh; - void *vl; +list2tq(void *vh, void *vl) { struct list_head_proto *h = (struct list_head_proto *)vh; 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. */ void -list_append(vl1, vl2) - void *vl1; - void *vl2; +list_append(void *vl1, void *vl2) { struct list_proto *l1 = (struct list_proto *)vl1; 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. */ void -tq_append(vh, vl) - void *vh; - void *vl; +tq_append(void *vh, void *vl) { struct list_head_proto *h = (struct list_head_proto *)vh; struct list_proto *l = (struct list_proto *)vl; @@ -136,9 +133,7 @@ tq_append(vh, vl) * Remove element from the tail_queue */ void -tq_remove(vh, vl) - void *vh; - void *vl; +tq_remove(void *vh, void *vl) { struct list_head_proto *h = (struct list_head_proto *)vh; struct list_proto *l = (struct list_proto *)vl; diff --git a/src/pty.c b/src/pty.c index bbb22f4e5..180b887ab 100644 --- a/src/pty.c +++ b/src/pty.c @@ -94,8 +94,7 @@ get_pty(int *master, int *slave, char *name, size_t namesz, uid_t uid) #elif defined(HAVE_GRANTPT) # ifndef HAVE_POSIX_OPENPT static int -posix_openpt(oflag) - int oflag; +posix_openpt(int oflag) { int fd; diff --git a/src/sesh.c b/src/sesh.c index 3195e25b9..38a834908 100644 --- a/src/sesh.c +++ b/src/sesh.c @@ -30,7 +30,7 @@ #include "compat.h" int -main (int argc, char **argv) +main (int argc, char *argv[]) { char *cp, *cmnd; diff --git a/src/sudo.c b/src/sudo.c index 7ff23eb4e..28210108b 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -583,8 +583,7 @@ disable_coredumps(void) * Cleanup hook for error()/errorx() */ void -cleanup(gotsignal) - int gotsignal; +cleanup(int gotsignal) { #if 0 /* XXX */ struct sudo_nss *nss; diff --git a/src/sudo_edit.c b/src/sudo_edit.c index 079c449bd..347eed94c 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -64,10 +64,7 @@ static char *find_editor(); * Wrapper to allow users to edit privileged files with their own uid. */ int -sudo_edit(argc, argv, envp) - int argc; - char **argv; - char **envp; +sudo_edit(int argc, char **argv, char **envp) { ssize_t nread, nwritten; pid_t kidpid, pid; @@ -350,7 +347,7 @@ cleanup: * the uid of the invoking user, not the runas (privileged) user. */ static char * -find_editor() +find_editor(void) { char *cp, *editor = NULL, **ev, *ev0[4]; diff --git a/src/term.c b/src/term.c index 221a28474..bb5156b94 100644 --- a/src/term.c +++ b/src/term.c @@ -105,9 +105,7 @@ int term_erase; int term_kill; int -term_restore(fd, flush) - int fd; - int flush; +term_restore(int fd, int flush) { if (changed) { int flags = TCSASOFT; @@ -120,8 +118,7 @@ term_restore(fd, flush) } int -term_noecho(fd) - int fd; +term_noecho(int fd) { if (!changed && tcgetattr(fd, &oterm) != 0) return(0); @@ -140,10 +137,7 @@ term_noecho(fd) #if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H) int -term_raw(fd, opost, isig) - int fd; - int opost; - int isig; +term_raw(int fd, int opost, int isig) { struct termios term; @@ -168,8 +162,7 @@ term_raw(fd, opost, isig) } int -term_cbreak(fd) - int fd; +term_cbreak(int fd) { if (!changed && tcgetattr(fd, &oterm) != 0) return(0); @@ -192,10 +185,7 @@ term_cbreak(fd) } int -term_copy(src, dst, opost) - int src; - int dst; - int opost; +term_copy(int src, int dst, int opost) { struct termios tt; @@ -213,9 +203,7 @@ term_copy(src, dst, opost) #else /* SGTTY */ int -term_raw(fd, onlcr) - int fd; - int onlcr; +term_raw(int fd, int onlcr) { if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) return(0); @@ -234,8 +222,7 @@ term_raw(fd, onlcr) } int -term_cbreak(fd) - int fd; +term_cbreak(int fd) { if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0) return(0); @@ -253,10 +240,7 @@ term_cbreak(fd) } int -term_copy(src, dst, onlcr) - int src; - int dst; - int onlcr; +term_copy(int src, int dst, int onlcr) { struct sgttyb b; struct tchars tc; diff --git a/src/zero_bytes.c b/src/zero_bytes.c index 7391780aa..de14ece39 100644 --- a/src/zero_bytes.c +++ b/src/zero_bytes.c @@ -24,9 +24,7 @@ * the compiler will not be able to optimize away this function. */ void -zero_bytes(v, n) - volatile void *v; - size_t n; +zero_bytes(volatile void *v, size_t n) { volatile char *p, *ep;