diff options
| author | christos <christos@NetBSD.org> | 2011-09-17 15:15:46 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2011-09-17 15:15:46 +0000 |
| commit | e16ddcd799edffda0db8c070ffb929413461db57 (patch) | |
| tree | ae337d51dea46c2a216b52a74880e7d57ac49915 | |
| parent | 17fe1c31e2deb2fc8d2a14e46c86090f4a0f84dc (diff) | |
ansify, const, knf
| -rw-r--r-- | usr.bin/tftp/extern.h | 6 | ||||
| -rw-r--r-- | usr.bin/tftp/main.c | 396 | ||||
| -rw-r--r-- | usr.bin/tftp/tftp.c | 14 | ||||
| -rw-r--r-- | usr.bin/tftp/tftpsubs.c | 59 | ||||
| -rw-r--r-- | usr.bin/tftp/tftpsubs.h | 16 |
5 files changed, 216 insertions, 275 deletions
diff --git a/usr.bin/tftp/extern.h b/usr.bin/tftp/extern.h index 2f18c258590..0c49275ebb5 100644 --- a/usr.bin/tftp/extern.h +++ b/usr.bin/tftp/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.6 2006/07/21 17:49:00 jmcneill Exp $ */ +/* $NetBSD: extern.h,v 1.7 2011/09/17 15:15:46 christos Exp $ */ /* * Copyright (c) 1993 @@ -47,5 +47,5 @@ extern uint16_t mcport; extern ushort mcmasterslave; extern struct sockaddr_storage peeraddr; /* filled in by main */ -void recvfile __P((int, char *, char *)); -void sendfile __P((int, char *, char *)); +void recvfile(int, const char *, const char *); +void sendfile(int, const char *, const char *); diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index d6d84c5dd99..ea6f130fd91 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2011/09/17 03:09:51 minskim Exp $ */ +/* $NetBSD: main.c,v 1.29 2011/09/17 15:15:46 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: main.c,v 1.28 2011/09/17 03:09:51 minskim Exp $"); +__RCSID("$NetBSD: main.c,v 1.29 2011/09/17 15:15:46 christos Exp $"); #endif #endif /* not lint */ @@ -46,6 +46,7 @@ __RCSID("$NetBSD: main.c,v 1.28 2011/09/17 03:09:51 minskim Exp $"); * TFTP User Program -- Command Interface. */ #include <sys/types.h> +#include <sys/param.h> #include <sys/socket.h> #include <netinet/in.h> @@ -77,74 +78,78 @@ int trace; int verbose; int tsize=0; int tout=0; -size_t def_blksize=SEGSIZE; -size_t blksize=SEGSIZE; +size_t def_blksize = SEGSIZE; +size_t blksize = SEGSIZE; in_addr_t mcaddr = INADDR_NONE; uint16_t mcport; +u_int def_rexmtval = TIMEOUT; +u_int rexmtval = TIMEOUT; ushort mcmasterslave; -int connected; -char mode[32]; -char line[LBUFLEN]; -int margc; -char *margv[20]; -const char *prompt = "tftp"; -jmp_buf toplevel; - -void get __P((int, char **)); -void help __P((int, char **)); -void modecmd __P((int, char **)); -void put __P((int, char **)); -__dead static void quit __P((int, char **)); -void setascii __P((int, char **)); -void setbinary __P((int, char **)); -void setpeer0 __P((const char *, const char *)); -void setpeer __P((int, char **)); -void setrexmt __P((int, char **)); -void settimeout __P((int, char **)); -void settrace __P((int, char **)); -void setverbose __P((int, char **)); -void setblksize __P((int, char **)); -void settsize __P((int, char **)); -void settimeoutopt __P((int, char **)); -void status __P((int, char **)); -char *tail __P((char *)); -int main __P((int, char *[])); -__dead static void intr __P((int)); -const struct cmd *getcmd __P((char *)); - -static __dead void command __P((void)); - -static void getusage __P((char *)); -static void makeargv __P((void)); -static void putusage __P((char *)); -static void settftpmode __P((const char *)); - -#define HELPINDENT (sizeof("connect")) +int maxtimeout = 5 * TIMEOUT; + +static int connected; +static char mode[32]; +static char line[LBUFLEN]; +static int margc; +static char *margv[20]; +static const char *prompt = "tftp"; +static char hostname[MAXHOSTNAMELEN]; +static jmp_buf toplevel; + +static void get(int, char **); +static void help(int, char **); +static void modecmd(int, char **); +static void put(int, char **); +static __dead void quit(int, char **); +static void setascii(int, char **); +static void setbinary(int, char **); +static void setpeer0(const char *, const char *); +static void setpeer(int, char **); +static void setrexmt(int, char **); +static void settimeout(int, char **); +static void settrace(int, char **); +static void setverbose(int, char **); +static void setblksize(int, char **); +static void settsize(int, char **); +static void settimeoutopt(int, char **); +static void status(int, char **); +static char *tail(char *); +static __dead void intr(int); +static const struct cmd *getcmd(const char *); + +static __dead void command(void); + +static void getUsage(char *); +static void makeargv(void); +static void putUsage(const char *); +static void settftpmode(const char *); + +#define HELPINDENT sizeof("connect") struct cmd { const char *name; const char *help; - void (*handler) __P((int, char **)); + void (*handler)(int, char **); }; -const char vhelp[] = "toggle verbose mode"; -const char thelp[] = "toggle packet tracing"; -const char tshelp[] = "toggle extended tsize option"; -const char tohelp[] = "toggle extended timeout option"; -const char blhelp[] = "set an alternative blocksize (def. 512)"; -const char chelp[] = "connect to remote tftp"; -const char qhelp[] = "exit tftp"; -const char hhelp[] = "print help information"; -const char shelp[] = "send file"; -const char rhelp[] = "receive file"; -const char mhelp[] = "set file transfer mode"; -const char sthelp[] = "show current status"; -const char xhelp[] = "set per-packet retransmission timeout"; -const char ihelp[] = "set total retransmission timeout"; -const char ashelp[] = "set mode to netascii"; -const char bnhelp[] = "set mode to octet"; - -const struct cmd cmdtab[] = { +static const char vhelp[] = "toggle verbose mode"; +static const char thelp[] = "toggle packet tracing"; +static const char tshelp[] = "toggle extended tsize option"; +static const char tohelp[] = "toggle extended timeout option"; +static const char blhelp[] = "set an alternative blocksize (def. 512)"; +static const char chelp[] = "connect to remote tftp"; +static const char qhelp[] = "exit tftp"; +static const char hhelp[] = "print help information"; +static const char shelp[] = "send file"; +static const char rhelp[] = "receive file"; +static const char mhelp[] = "set file transfer mode"; +static const char sthelp[] = "show current status"; +static const char xhelp[] = "set per-packet retransmission timeout"; +static const char ihelp[] = "set total retransmission timeout"; +static const char ashelp[] = "set mode to netascii"; +static const char bnhelp[] = "set mode to octet"; + +static const struct cmd cmdtab[] = { { "connect", chelp, setpeer }, { "mode", mhelp, modecmd }, { "put", shelp, put }, @@ -164,10 +169,21 @@ const struct cmd cmdtab[] = { { .name = NULL } }; +static struct modes { + const char *m_name; + const char *m_mode; +} modes[] = { + { "ascii", "netascii" }, + { "netascii", "netascii" }, + { "binary", "octet" }, + { "image", "octet" }, + { "octet", "octet" }, +/* { "mail", "mail" }, */ + { 0, 0 } +}; + int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int c; @@ -185,8 +201,8 @@ main(argc, argv) tout = 1; break; default: - (void)printf("usage: %s [-e] host-name [port]\n", - getprogname()); + (void)fprintf(stderr, + "Usage: %s [-e] host-name [port]\n", getprogname()); exit(1); } } @@ -203,15 +219,20 @@ main(argc, argv) if (setjmp(toplevel) != 0) (void)putchar('\n'); command(); - return (0); + return 0; } -char hostname[100]; +static void +getmore(const char *cmd, const char *prm) +{ + (void)strlcpy(line, cmd, sizeof(line)); + (void)printf("%s", prm); + (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); + makeargv(); +} -void -setpeer0(host, port) - const char *host; - const char *port; +static void +setpeer0(const char *host, const char *port) { struct addrinfo hints, *res0, *res; int error, soopt; @@ -241,7 +262,7 @@ setpeer0(host, port) if (res->ai_addrlen > sizeof(peeraddr)) continue; f = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (f < 0) { + if (f == -1) { cause = "socket"; continue; } @@ -250,7 +271,7 @@ setpeer0(host, port) ss.ss_family = res->ai_family; ss.ss_len = res->ai_addrlen; if (bind(f, (struct sockaddr *)(void *)&ss, - (socklen_t)ss.ss_len) < 0) { + (socklen_t)ss.ss_len) == -1) { cause = "bind"; (void)close(f); f = -1; @@ -263,20 +284,20 @@ setpeer0(host, port) if (f >= 0) { soopt = 65536; if (setsockopt(f, SOL_SOCKET, SO_SNDBUF, &soopt, sizeof(soopt)) - < 0) { + == -1) { (void)close(f); f = -1; cause = "setsockopt SNDBUF"; } - else if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt, sizeof(soopt)) - < 0) { + else if (setsockopt(f, SOL_SOCKET, SO_RCVBUF, &soopt, + sizeof(soopt)) == -1) { (void)close(f); f = -1; cause = "setsockopt RCVBUF"; } } - if (f < 0 || res == NULL) + if (f == -1 || res == NULL) warn("%s", cause); else { /* res->ai_addr <= sizeof(peeraddr) is guaranteed */ @@ -292,22 +313,18 @@ setpeer0(host, port) freeaddrinfo(res0); } -void -setpeer(argc, argv) - int argc; - char *argv[]; +static void +setpeer(int argc, char *argv[]) { if (argc < 2) { - (void)strlcpy(line, "Connect ", sizeof(line)); - (void)printf("(to) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("Connect ", "(to) "); argc = margc; argv = margv; } - if ((argc < 2) || (argc > 3)) { - (void)printf("usage: %s [-e] host-name [port]\n", getprogname()); + if (argc < 2 || argc > 3) { + (void)printf("Usage: %s [-e] host-name [port]\n", + getprogname()); return; } if (argc == 2) @@ -316,23 +333,8 @@ setpeer(argc, argv) setpeer0(argv[1], argv[2]); } -struct modes { - const char *m_name; - const char *m_mode; -} modes[] = { - { "ascii", "netascii" }, - { "netascii", "netascii" }, - { "binary", "octet" }, - { "image", "octet" }, - { "octet", "octet" }, -/* { "mail", "mail" }, */ - { 0, 0 } -}; - -void -modecmd(argc, argv) - int argc; - char *argv[]; +static void +modecmd(int argc, char *argv[]) { struct modes *p; const char *sep; @@ -350,10 +352,10 @@ modecmd(argc, argv) return; } (void)printf("%s: unknown mode\n", argv[1]); - /* drop through and print usage message */ + /* drop through and print Usage message */ } - (void)printf("usage: %s [", argv[0]); + (void)printf("Usage: %s [", argv[0]); sep = " "; for (p = modes; p->m_name; p++) { (void)printf("%s%s", sep, p->m_name); @@ -364,29 +366,24 @@ modecmd(argc, argv) return; } -void +static void /*ARGSUSED*/ -setbinary(argc, argv) - int argc; - char *argv[]; +setbinary(int argc, char *argv[]) { settftpmode("octet"); } -void +static void /*ARGSUSED*/ -setascii(argc, argv) - int argc; - char *argv[]; +setascii(int argc, char *argv[]) { settftpmode("netascii"); } static void -settftpmode(newmode) - const char *newmode; +settftpmode(const char *newmode) { (void)strlcpy(mode, newmode, sizeof(mode)); if (verbose) @@ -397,25 +394,20 @@ settftpmode(newmode) /* * Send file(s). */ -void -put(argc, argv) - int argc; - char *argv[]; +static void +put(int argc, char *argv[]) { int fd; int n; char *targ, *p; if (argc < 2) { - (void)strlcpy(line, "send ", sizeof(line)); - (void)printf("(file) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("send ", "(file) "); argc = margc; argv = margv; } if (argc < 2) { - putusage(argv[0]); + putUsage(argv[0]); return; } targ = argv[argc - 1]; @@ -424,7 +416,7 @@ put(argc, argv) for (n = 1; n < argc - 1; n++) if (strchr(argv[n], ':')) { - putusage(argv[0]); + putUsage(argv[0]); return; } cp = argv[argc - 1]; @@ -443,7 +435,7 @@ put(argc, argv) if (argc < 4) { char *cp = argc == 2 ? tail(targ) : argv[1]; fd = open(cp, O_RDONLY); - if (fd < 0) { + if (fd == -1) { warn("%s", cp); return; } @@ -460,7 +452,7 @@ put(argc, argv) for (n = 1; n < argc - 1; n++) { (void)strcpy(p, tail(argv[n])); fd = open(argv[n], O_RDONLY); - if (fd < 0) { + if (fd == -1) { warn("%s", argv[n]); continue; } @@ -472,20 +464,17 @@ put(argc, argv) } static void -putusage(s) - char *s; +putUsage(const char *s) { - (void)printf("usage: %s file ... host:target, or\n", s); + (void)printf("Usage: %s file ... host:target, or\n", s); (void)printf(" %s file ... target (when already connected)\n", s); } /* * Receive file(s). */ -void -get(argc, argv) - int argc; - char *argv[]; +static void +get(int argc, char *argv[]) { int fd; int n; @@ -493,21 +482,18 @@ get(argc, argv) char *src; if (argc < 2) { - (void)strlcpy(line, "get ", sizeof(line)); - (void)printf("(files) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("get ", "(files) "); argc = margc; argv = margv; } if (argc < 2) { - getusage(argv[0]); + getUsage(argv[0]); return; } if (!connected) { for (n = 1; n < argc ; n++) if (strrchr(argv[n], ':') == 0) { - getusage(argv[0]); + getUsage(argv[0]); return; } } @@ -530,7 +516,7 @@ get(argc, argv) if (argc < 4) { char *cp = argc == 3 ? argv[2] : tail(src); fd = creat(cp, 0644); - if (fd < 0) { + if (fd == -1) { warn("%s", cp); return; } @@ -542,7 +528,7 @@ get(argc, argv) } p = tail(src); /* new .. jdg */ fd = creat(p, 0644); - if (fd < 0) { + if (fd == -1) { warn("%s", p); continue; } @@ -554,10 +540,10 @@ get(argc, argv) } static void -getusage(s) +getUsage(s) char *s; { - (void)printf("usage: %s host:file host:file ... file, or\n", s); + (void)printf("Usage: %s host:file host:file ... file, or\n", s); (void)printf(" %s file file ... file if connected\n", s); } @@ -569,15 +555,12 @@ setblksize(argc, argv) int t; if (argc < 2) { - (void)strlcpy(line, "blksize ", sizeof(line)); - (void)printf("(blksize) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("blksize ", "(blksize) "); argc = margc; argv = margv; } if (argc != 2) { - (void)printf("usage: %s value\n", argv[0]); + (void)printf("Usage: %s value\n", argv[0]); return; } t = atoi(argv[1]); @@ -587,26 +570,18 @@ setblksize(argc, argv) blksize = t; } -unsigned int def_rexmtval = TIMEOUT; -unsigned int rexmtval = TIMEOUT; - -void -setrexmt(argc, argv) - int argc; - char *argv[]; +static void +setrexmt(int argc, char *argv[]) { int t; if (argc < 2) { - (void)strlcpy(line, "Rexmt-timeout ", sizeof(line)); - (void)printf("(value) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("Rexmt-timeout ", "(value) "); argc = margc; argv = margv; } if (argc != 2) { - (void)printf("usage: %s value\n", argv[0]); + (void)printf("Usage: %s value\n", argv[0]); return; } t = atoi(argv[1]); @@ -616,25 +591,18 @@ setrexmt(argc, argv) rexmtval = t; } -int maxtimeout = 5 * TIMEOUT; - -void -settimeout(argc, argv) - int argc; - char *argv[]; +static void +settimeout(int argc, char *argv[]) { int t; if (argc < 2) { - (void)strlcpy(line, "Maximum-timeout ", sizeof(line)); - (void)printf("(value) "); - (void)fgets(&line[strlen(line)], (int)(LBUFLEN-strlen(line)), stdin); - makeargv(); + getmore("Maximum-timeout ", "(value) "); argc = margc; argv = margv; } if (argc != 2) { - (void)printf("usage: %s value\n", argv[0]); + (void)printf("Usage: %s value\n", argv[0]); return; } t = atoi(argv[1]); @@ -644,11 +612,9 @@ settimeout(argc, argv) maxtimeout = t; } -void +static void /*ARGSUSED*/ -status(argc, argv) - int argc; - char *argv[]; +status(int argc, char *argv[]) { if (connected) (void)printf("Connected to %s.\n", hostname); @@ -660,10 +626,9 @@ status(argc, argv) rexmtval, maxtimeout); } -void +static void /*ARGSUSED*/ -intr(dummy) - int dummy; +intr(int dummy) { (void)signal(SIGALRM, SIG_IGN); @@ -671,9 +636,8 @@ intr(dummy) longjmp(toplevel, -1); } -char * -tail(filename) - char *filename; +static char * +tail(char *filename) { char *s; @@ -682,17 +646,17 @@ tail(filename) if (s == NULL) break; if (s[1]) - return (s + 1); + return s + 1; *s = '\0'; } - return (filename); + return filename; } /* * Command parser. */ static __dead void -command() +command(void) { const struct cmd *c; @@ -705,7 +669,7 @@ command() continue; } } - if ((line[0] == 0) || (line[0] == '\n')) + if (line[0] == '\0' || line[0] == '\n') continue; makeargv(); if (margc == 0) @@ -723,9 +687,8 @@ command() } } -const struct cmd * -getcmd(name) - char *name; +static const struct cmd * +getcmd(const char *name) { const char *p, *q; const struct cmd *c, *found; @@ -737,7 +700,7 @@ getcmd(name) for (c = cmdtab; (p = c->name) != NULL; c++) { for (q = name; *q == *p++; q++) if (*q == 0) /* exact match? */ - return (c); + return c; if (!*q) { /* the name was a prefix */ if (q - name > longest) { longest = q - name; @@ -748,15 +711,15 @@ getcmd(name) } } if (nmatches > 1) - return ((struct cmd *)-1); - return (found); + return (struct cmd *)-1; + return found; } /* * Slice a string up into argc/argv. */ static void -makeargv() +makeargv(void) { char *cp; char **argp = margv; @@ -775,14 +738,12 @@ makeargv() break; *cp++ = '\0'; } - *argp++ = 0; + *argp++ = NULL; } -void +static void /*ARGSUSED*/ -quit(argc, argv) - int argc; - char *argv[]; +quit(int argc, char *argv[]) { exit(0); @@ -791,17 +752,16 @@ quit(argc, argv) /* * Help command. */ -void -help(argc, argv) - int argc; - char *argv[]; +static void +help(int argc, char *argv[]) { const struct cmd *c; if (argc == 1) { (void)printf("Commands may be abbreviated. Commands are:\n\n"); for (c = cmdtab; c->name; c++) - (void)printf("%-*s\t%s\n", (int)HELPINDENT, c->name, c->help); + (void)printf("%-*s\t%s\n", (int)HELPINDENT, c->name, + c->help); return; } while (--argc > 0) { @@ -810,48 +770,40 @@ help(argc, argv) c = getcmd(arg); if (c == (struct cmd *)-1) (void)printf("?Ambiguous help command %s\n", arg); - else if (c == (struct cmd *)0) + else if (c == NULL) (void)printf("?Invalid help command %s\n", arg); else (void)printf("%s\n", c->help); } } -void +static void /*ARGSUSED*/ -settrace(argc, argv) - int argc; - char **argv; +settrace(int argc, char **argv) { trace = !trace; (void)printf("Packet tracing %s.\n", trace ? "on" : "off"); } -void +static void /*ARGSUSED*/ -setverbose(argc, argv) - int argc; - char **argv; +setverbose(int argc, char **argv) { verbose = !verbose; (void)printf("Verbose mode %s.\n", verbose ? "on" : "off"); } -void +static void /*ARGSUSED*/ -settsize(argc, argv) - int argc; - char **argv; +settsize(int argc, char **argv) { tsize = !tsize; (void)printf("Tsize mode %s.\n", tsize ? "on" : "off"); } -void +static void /*ARGSUSED*/ -settimeoutopt(argc, argv) - int argc; - char **argv; +settimeoutopt(int argc, char **argv) { tout = !tout; (void)printf("Timeout option %s.\n", tout ? "on" : "off"); diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c index e516400ea98..86bc575fceb 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -1,4 +1,4 @@ -/* $NetBSD: tftp.c,v 1.31 2011/09/16 15:39:30 joerg Exp $ */ +/* $NetBSD: tftp.c,v 1.32 2011/09/17 15:15:46 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tftp.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: tftp.c,v 1.31 2011/09/16 15:39:30 joerg Exp $"); +__RCSID("$NetBSD: tftp.c,v 1.32 2011/09/17 15:15:46 christos Exp $"); #endif #endif /* not lint */ @@ -218,10 +218,7 @@ tftp_igmp_leave(int fd) * Send the requested file. */ void -sendfile(fd, name, mode) - int fd; - char *name; - char *mode; +sendfile(int fd, const char *name, const char *mode) { struct tftphdr *ap; /* data and ack packets */ struct tftphdr *dp; @@ -370,10 +367,7 @@ abort: * Receive a file. */ void -recvfile(fd, name, mode) - int fd; - char *name; - char *mode; +recvfile(int fd, const char *name, const char *mode) { struct tftphdr *ap; struct tftphdr *dp; diff --git a/usr.bin/tftp/tftpsubs.c b/usr.bin/tftp/tftpsubs.c index 2a60b9921f4..a2e834de036 100644 --- a/usr.bin/tftp/tftpsubs.c +++ b/usr.bin/tftp/tftpsubs.c @@ -1,4 +1,4 @@ -/* $NetBSD: tftpsubs.c,v 1.11 2009/01/18 07:11:45 lukem Exp $ */ +/* $NetBSD: tftpsubs.c,v 1.12 2011/09/17 15:15:46 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tftpsubs.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: tftpsubs.c,v 1.11 2009/01/18 07:11:45 lukem Exp $"); +__RCSID("$NetBSD: tftpsubs.c,v 1.12 2011/09/17 15:15:46 christos Exp $"); #endif #endif /* not lint */ @@ -60,7 +60,7 @@ __RCSID("$NetBSD: tftpsubs.c,v 1.11 2009/01/18 07:11:45 lukem Exp $"); #include "tftpsubs.h" -struct bf { +static struct bf { int counter; /* size of data in buffer, or flag */ char buf[MAXPKTSIZE]; /* room for data packet */ } bfs[2]; @@ -74,26 +74,26 @@ static int nextone; /* index of next buffer to use */ static int current; /* index of buffer in use */ /* control flags for crlf conversions */ -int newline = 0; /* fillbuf: in middle of newline expansion */ -int prevchar = -1; /* putbuf: previous char (cr check) */ +static int newline = 0; /* fillbuf: in middle of newline expansion */ +static int prevchar = -1; /* putbuf: previous char (cr check) */ -static struct tftphdr *rw_init __P((int)); +static struct tftphdr *rw_init(int); struct tftphdr * -w_init() /* write-behind */ +w_init(void) /* write-behind */ { return rw_init(0); } struct tftphdr * -r_init() /* read-ahead */ +r_init(void) /* read-ahead */ { return rw_init(1); } static struct tftphdr * -rw_init(x) /* init for either read-ahead or write-behind */ - int x; /* zero for write-behind, one for read-head */ +rw_init(int x) /* init for either read-ahead or write-behind */ + /* zero for write-behind, one for read-head */ { newline = 0; /* init crlf flag */ prevchar = -1; @@ -108,11 +108,11 @@ rw_init(x) /* init for either read-ahead or write-behind */ Free it and return next buffer filled with data. */ int -readit(file, dpp, amt, convert) - FILE *file; /* file opened for read */ - struct tftphdr **dpp; - size_t amt; - int convert; /* if true, convert to ascii */ +readit( + FILE *file, /* file opened for read */ + struct tftphdr **dpp, + size_t amt, + int convert) /* if true, convert to ascii */ { struct bf *b; @@ -132,10 +132,10 @@ readit(file, dpp, amt, convert) * conversions are lf -> cr,lf and cr -> cr, nul */ void -read_ahead(file, amt, convert) - FILE *file; /* file opened for read */ - size_t amt; /* number of bytes to read */ - int convert; /* if true, convert to ascii */ +read_ahead( + FILE *file, /* file opened for read */ + size_t amt, /* number of bytes to read */ + int convert) /* if true, convert to ascii */ { size_t i; char *p; @@ -182,10 +182,7 @@ read_ahead(file, amt, convert) available. */ int -writeit(file, dpp, ct, convert) - FILE *file; - struct tftphdr **dpp; - int ct, convert; +writeit(FILE *file, struct tftphdr **dpp, int ct, int convert) { bfs[current].counter = ct; /* set size of data to write */ current = !current; /* switch to other buffer */ @@ -204,9 +201,7 @@ writeit(file, dpp, ct, convert) * CR followed by anything else. In this case we leave it alone. */ int -write_behind(file, convert) - FILE *file; - int convert; +write_behind(FILE *file, int convert) { char *buf; int count; @@ -265,9 +260,9 @@ skipit: int /*ARGSUSED*/ -synchnet(f, bsize) - int f; /* socket to flush */ - size_t bsize; /* size of buffer to sync */ +synchnet( + int f, /* socket to flush */ + size_t bsize) /* size of buffer to sync */ { int i, j = 0; char rbuf[PKTSIZE]; @@ -279,10 +274,10 @@ synchnet(f, bsize) if (i) { j++; fromlen = sizeof from; - (void) recvfrom(f, rbuf, sizeof (rbuf), 0, - (struct sockaddr *)(void *)&from, &fromlen); + (void)recvfrom(f, rbuf, sizeof (rbuf), 0, + (struct sockaddr *)(void *)&from, &fromlen); } else { - return(j); + return j; } } } diff --git a/usr.bin/tftp/tftpsubs.h b/usr.bin/tftp/tftpsubs.h index 2ad50e57e19..0533dc7c85d 100644 --- a/usr.bin/tftp/tftpsubs.h +++ b/usr.bin/tftp/tftpsubs.h @@ -1,4 +1,4 @@ -/* $NetBSD: tftpsubs.h,v 1.5 2006/01/31 17:36:56 christos Exp $ */ +/* $NetBSD: tftpsubs.h,v 1.6 2011/09/17 15:15:46 christos Exp $ */ /* * Copyright (c) 1993 @@ -35,12 +35,12 @@ * Prototypes for read-ahead/write-behind subroutines for tftp user and * server. */ -struct tftphdr *r_init __P((void)); -void read_ahead __P((FILE *, size_t, int)); -int readit __P((FILE *, struct tftphdr **, size_t, int)); +struct tftphdr *r_init(void); +void read_ahead(FILE *, size_t, int); +int readit(FILE *, struct tftphdr **, size_t, int); -int synchnet __P((int, size_t)); +int synchnet(int, size_t); -struct tftphdr *w_init __P((void)); -int write_behind __P((FILE *, int)); -int writeit __P((FILE *, struct tftphdr **, int, int)); +struct tftphdr *w_init(void); +int write_behind(FILE *, int); +int writeit(FILE *, struct tftphdr **, int, int); |
