From a78cd7563c9ec3cf7b234be12c4928541ec8bb41 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Fri, 19 Mar 2004 17:17:46 +0000 Subject: [PATCH] Clean up the code in bin/ to reduce warnings from GCC3. Stage 2 of 5 or so: small cleanups across several programs. - Convert ``quad'' types to ``long long''. - Convert appropriate ``int'' types to ``size_t''. - Fix comment syntax to use /* */ instead of //. - Initialize a variable before using it. - Remove an unneeded cast. Submitted-by: Simon 'corecode' Schubert --- bin/dd/args.c | 6 +++--- bin/dd/misc.c | 10 +++++----- bin/expr/expr.y | 4 ++-- bin/hostname/hostname.c | 8 ++++---- bin/ln/ln.c | 4 ++-- bin/ls/ls.c | 4 ++-- bin/rcp/rcp.c | 5 +++-- bin/rcp/util.c | 3 ++- bin/test/test.c | 18 +++++++++--------- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/bin/dd/args.c b/bin/dd/args.c index fd97eb9b73..4e6bf0b768 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -36,7 +36,7 @@ * * @(#)args.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/bin/dd/args.c,v 1.25.2.2 2001/01/23 14:20:03 asmodai Exp $ - * $DragonFly: src/bin/dd/args.c,v 1.4 2003/09/28 14:39:13 hmp Exp $ + * $DragonFly: src/bin/dd/args.c,v 1.5 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -164,7 +164,7 @@ jcl(char **argv) * Bail out if the calculation of a file offset would overflow. */ if (in.offset > QUAD_MAX / in.dbsz || out.offset > QUAD_MAX / out.dbsz) - errx(1, "seek offsets cannot be larger than %qd", QUAD_MAX); + errx(1, "seek offsets cannot be larger than %lld", QUAD_MAX); } static int @@ -340,7 +340,7 @@ get_num(char *val) char *expr; errno = 0; - num = strtoq(val, &expr, 0); + num = strtoll(val, &expr, 0); if (errno != 0) /* Overflow or underflow. */ err(1, "%s", oper); diff --git a/bin/dd/misc.c b/bin/dd/misc.c index 2062681243..d1160385dc 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -36,7 +36,7 @@ * * @(#)misc.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/bin/dd/misc.c,v 1.18.2.1 2001/08/01 01:40:03 obrien Exp $ - * $DragonFly: src/bin/dd/misc.c,v 1.3 2003/09/28 14:39:13 hmp Exp $ + * $DragonFly: src/bin/dd/misc.c,v 1.4 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -64,21 +64,21 @@ summary(void) secs = 1e-6; /* Use snprintf(3) so that we don't reenter stdio(3). */ (void)snprintf(buf, sizeof(buf), - "%qu+%qu records in\n%qu+%qu records out\n", + "%llu+%llu records in\n%llu+%llu records out\n", st.in_full, st.in_part, st.out_full, st.out_part); (void)write(STDERR_FILENO, buf, strlen(buf)); if (st.swab) { - (void)snprintf(buf, sizeof(buf), "%qu odd length swab %s\n", + (void)snprintf(buf, sizeof(buf), "%llu odd length swab %s\n", st.swab, (st.swab == 1) ? "block" : "blocks"); (void)write(STDERR_FILENO, buf, strlen(buf)); } if (st.trunc) { - (void)snprintf(buf, sizeof(buf), "%qu truncated %s\n", + (void)snprintf(buf, sizeof(buf), "%llu truncated %s\n", st.trunc, (st.trunc == 1) ? "block" : "blocks"); (void)write(STDERR_FILENO, buf, strlen(buf)); } (void)snprintf(buf, sizeof(buf), - "%qu bytes transferred in %.6f secs (%.0f bytes/sec)\n", + "%llu bytes transferred in %.6f secs (%.0f bytes/sec)\n", st.bytes, secs, st.bytes / secs); (void)write(STDERR_FILENO, buf, strlen(buf)); } diff --git a/bin/expr/expr.y b/bin/expr/expr.y index 92143c6fa0..b26361aa50 100644 --- a/bin/expr/expr.y +++ b/bin/expr/expr.y @@ -5,7 +5,7 @@ * Largely rewritten by J.T. Conklin (jtc@wimsey.com) * * $FreeBSD: src/bin/expr/expr.y,v 1.14.2.3 2001/08/01 02:37:46 obrien Exp $ - * $DragonFly: src/bin/expr/expr.y,v 1.3 2003/09/21 04:21:56 drhodus Exp $ + * $DragonFly: src/bin/expr/expr.y,v 1.4 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -175,7 +175,7 @@ struct val *vp; /* vp->type == numeric_string, make it numeric */ errno = 0; - i = strtoq(vp->u.s, (char**)NULL, 10); + i = strtoll(vp->u.s, (char**)NULL, 10); if (errno != 0) { errx (2, "overflow"); } diff --git a/bin/hostname/hostname.c b/bin/hostname/hostname.c index f1c179192b..ac45ebd27b 100644 --- a/bin/hostname/hostname.c +++ b/bin/hostname/hostname.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1988, 1993 The Regents of the University of California. All rights reserved. * @(#)hostname.c 8.1 (Berkeley) 5/31/93 * $FreeBSD: src/bin/hostname/hostname.c,v 1.10.2.1 2001/08/01 02:40:23 obrien Exp $ - * $DragonFly: src/bin/hostname/hostname.c,v 1.6 2004/01/20 00:54:09 dillon Exp $ + * $DragonFly: src/bin/hostname/hostname.c,v 1.7 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -107,13 +107,13 @@ main(int argc, char **argv) { int ch,sflag,rflag,ret,flag6,iflag; char hostname[MAXHOSTNAMELEN]; - char *srflag,*siflag; + char *srflag, *siflag = NULL; struct hostent *hst; struct in_addr ia; struct in6_addr ia6; int mib[6]; - int needed; + size_t needed; char *buf,*lim,*next,*p; int idx; struct sockaddr_dl *sdl; @@ -294,7 +294,7 @@ main(int argc, char **argv) } else if (rflag) { ret = inet_pton(AF_INET, srflag, &ia); if (ret != 1) { - // check IPV6 + /* check IPV6 */ ret = inet_pton(AF_INET6, srflag, &ia6); if (ret != 1) { diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 278d510f00..22cd1c070f 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1987, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)ln.c 8.2 (Berkeley) 3/31/94 * $FreeBSD: src/bin/ln/ln.c,v 1.15.2.4 2002/07/12 07:34:38 tjr Exp $ - * $DragonFly: src/bin/ln/ln.c,v 1.2 2003/06/17 04:22:50 dillon Exp $ + * $DragonFly: src/bin/ln/ln.c,v 1.3 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -181,7 +181,7 @@ linkit(const char *target, const char *source, int isdir) else ++p; if (snprintf(path, sizeof(path), "%s/%s", source, p) >= - sizeof(path)) { + (int)sizeof(path)) { errno = ENAMETOOLONG; warn("%s", target); return (1); diff --git a/bin/ls/ls.c b/bin/ls/ls.c index f53eb2b00f..0156e92dbf 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -36,7 +36,7 @@ * @(#) Copyright (c) 1989, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)ls.c 8.5 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ls/ls.c,v 1.32.2.8 2002/11/17 10:27:34 tjr Exp $ - * $DragonFly: src/bin/ls/ls.c,v 1.2 2003/06/17 04:22:50 dillon Exp $ + * $DragonFly: src/bin/ls/ls.c,v 1.3 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -707,7 +707,7 @@ display(FTSENT *p, FTSENT *list) d.s_inode = strlen(buf); (void)snprintf(buf, sizeof(buf), "%lu", maxnlink); d.s_nlink = strlen(buf); - (void)snprintf(buf, sizeof(buf), "%qu", maxsize); + (void)snprintf(buf, sizeof(buf), "%llu", maxsize); d.s_size = strlen(buf); d.s_user = maxuser; } diff --git a/bin/rcp/rcp.c b/bin/rcp/rcp.c index f1f4adb87c..c317bb15b7 100644 --- a/bin/rcp/rcp.c +++ b/bin/rcp/rcp.c @@ -40,7 +40,7 @@ * @(#) Copyright (c) 1983, 1990, 1992, 1993 The Regents of the University of California. All rights reserved. * @(#)rcp.c 8.2 (Berkeley) 4/2/94 * $FreeBSD: src/bin/rcp/rcp.c,v 1.26.2.5 2002/08/16 20:06:34 ume Exp $ - * $DragonFly: src/bin/rcp/rcp.c,v 1.2 2003/06/17 04:22:50 dillon Exp $ + * $DragonFly: src/bin/rcp/rcp.c,v 1.3 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -578,7 +578,8 @@ sink(int argc, char *argv[]) enum { YES, NO, DISPLAYED } wrerr; BUF *bp; off_t i, j, size; - int amt, count, exists, first, mask, mode, ofd, omode; + size_t amt, count; + int exists, first, mask, mode, ofd, omode; int setimes, targisdir, wrerrno = 0; char ch, *cp, *np, *targ, *why, *vect[1], buf[BUFSIZ]; diff --git a/bin/rcp/util.c b/bin/rcp/util.c index 9ce7ebbefb..73eed57b83 100644 --- a/bin/rcp/util.c +++ b/bin/rcp/util.c @@ -32,7 +32,7 @@ * * @(#)util.c 8.2 (Berkeley) 4/2/94 * $FreeBSD: src/bin/rcp/util.c,v 1.9.2.3 2002/07/19 07:54:51 jmallett Exp $ - * $DragonFly: src/bin/rcp/util.c,v 1.2 2003/06/17 04:22:50 dillon Exp $ + * $DragonFly: src/bin/rcp/util.c,v 1.3 2004/03/19 17:17:46 cpressey Exp $ */ #include @@ -150,6 +150,7 @@ allocbuf(BUF *bp, int fd, int blksize) return (bp); } +/* ARGSUSED */ void lostconn(int signo) { diff --git a/bin/test/test.c b/bin/test/test.c index fcbcd9cddf..5038e20104 100644 --- a/bin/test/test.c +++ b/bin/test/test.c @@ -10,7 +10,7 @@ * This program is in the Public Domain. * * $FreeBSD: src/bin/test/test.c,v 1.29.2.7 2002/09/10 09:10:57 maxim Exp $ - * $DragonFly: src/bin/test/test.c,v 1.4 2003/09/28 14:39:15 hmp Exp $ + * $DragonFly: src/bin/test/test.c,v 1.5 2004/03/19 17:17:45 cpressey Exp $ */ #include @@ -178,7 +178,7 @@ static int binop (void); static int equalf (const char *, const char *); static int filstat (char *, enum token); static int getn (const char *); -static quad_t getq (const char *); +static long long getll (const char *); static int intcmp (const char *, const char *); static int isoperand (void); static int newerf (const char *, const char *); @@ -486,14 +486,14 @@ getn(const char *s) } /* atoi with error detection and 64 bit range */ -static quad_t -getq(const char *s) +static long long +getll(const char *s) { char *p; - quad_t r; + long long r; errno = 0; - r = strtoq(s, &p, 10); + r = strtoll(s, &p, 10); if (errno != 0) error((errno == EINVAL) ? "%s: bad number" : @@ -511,11 +511,11 @@ getq(const char *s) static int intcmp (const char *s1, const char *s2) { - quad_t q1, q2; + long long q1, q2; - q1 = getq(s1); - q2 = getq(s2); + q1 = getll(s1); + q2 = getll(s2); if (q1 > q2) return 1; -- 2.41.0