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
CC = @CC@
NROFF = nroff -Tascii
# Our install program supports extra flags...
INSTALL = $(SHELL) $(top_srcdir)/install-sh -c

View File

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

View File

@@ -46,7 +46,9 @@
# include <inttypes.h>
#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);

View File

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

View File

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

View File

@@ -47,7 +47,7 @@
# include <emul/timespec.h>
#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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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