From 4a5947c3398526e4dd988d5e2f1ba3498295e263 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 15 Mar 2004 16:24:22 +0000 Subject: [PATCH] Code cleanup, remove 'register' and (void) casts. No functional changes. Submitted-by: Chris Pressey --- usr.sbin/mtree/compare.c | 62 +++++++++++++++++++------------------- usr.sbin/mtree/create.c | 63 ++++++++++++++++++++------------------- usr.sbin/mtree/excludes.c | 3 +- usr.sbin/mtree/misc.c | 3 +- usr.sbin/mtree/mtree.c | 7 +++-- usr.sbin/mtree/spec.c | 14 ++++----- usr.sbin/mtree/verify.c | 58 +++++++++++++++++------------------ 7 files changed, 107 insertions(+), 103 deletions(-) diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index f9868c2be0..5fddafd0e0 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -32,7 +32,7 @@ * * @(#)compare.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/compare.c,v 1.15.2.4 2003/05/07 17:55:17 tobez Exp $ - * $DragonFly: src/usr.sbin/mtree/compare.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/compare.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -69,7 +69,7 @@ static char *ftype(u_int); } int -compare(char *name, register NODE *s, register FTSENT *p) +compare(char *name, NODE *s, FTSENT *p) { extern int uflag; u_long len, val; @@ -106,7 +106,7 @@ compare(char *name, register NODE *s, register FTSENT *p) case F_SOCK: if (!S_ISSOCK(p->fts_statp->st_mode)) { typeerr: LABEL; - (void)printf("\ttype expected %s found %s\n", + printf("\ttype expected %s found %s\n", ftype(s->type), inotype(p->fts_statp->st_mode)); return (label); } @@ -115,59 +115,59 @@ typeerr: LABEL; /* Set the uid/gid first, then set the mode. */ if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { LABEL; - (void)printf("%suser expected %lu found %lu", + printf("%suser expected %lu found %lu", tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid); if (uflag) if (chown(p->fts_accpath, s->st_uid, -1)) - (void)printf(" not modified: %s\n", + printf(" not modified: %s\n", strerror(errno)); else - (void)printf(" modified\n"); + printf(" modified\n"); else - (void)printf("\n"); + printf("\n"); tab = "\t"; } if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { LABEL; - (void)printf("%sgid expected %lu found %lu", + printf("%sgid expected %lu found %lu", tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid); if (uflag) if (chown(p->fts_accpath, -1, s->st_gid)) - (void)printf(" not modified: %s\n", + printf(" not modified: %s\n", strerror(errno)); else - (void)printf(" modified\n"); + printf(" modified\n"); else - (void)printf("\n"); + printf("\n"); tab = "\t"; } if (s->flags & F_MODE && !S_ISLNK(p->fts_statp->st_mode) && s->st_mode != (p->fts_statp->st_mode & MBITS)) { LABEL; - (void)printf("%spermissions expected %#o found %#o", + printf("%spermissions expected %#o found %#o", tab, s->st_mode, p->fts_statp->st_mode & MBITS); if (uflag) if (chmod(p->fts_accpath, s->st_mode)) - (void)printf(" not modified: %s\n", + printf(" not modified: %s\n", strerror(errno)); else - (void)printf(" modified\n"); + printf(" modified\n"); else - (void)printf("\n"); + printf("\n"); tab = "\t"; } if (s->flags & F_NLINK && s->type != F_DIR && s->st_nlink != p->fts_statp->st_nlink) { LABEL; - (void)printf("%slink_count expected %u found %u\n", + printf("%slink_count expected %u found %u\n", tab, s->st_nlink, p->fts_statp->st_nlink); tab = "\t"; } if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size && !S_ISDIR(p->fts_statp->st_mode)) { LABEL; - (void)printf("%ssize expected %qd found %qd\n", + printf("%ssize expected %qd found %qd\n", tab, s->st_size, p->fts_statp->st_size); tab = "\t"; } @@ -179,29 +179,29 @@ typeerr: LABEL; ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec) || (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec))) { LABEL; - (void)printf("%smodification time expected %.24s ", + printf("%smodification time expected %.24s ", tab, ctime(&s->st_mtimespec.tv_sec)); - (void)printf("found %.24s\n", + printf("found %.24s\n", ctime(&p->fts_statp->st_mtimespec.tv_sec)); tab = "\t"; } if (s->flags & F_CKSUM) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { LABEL; - (void)printf("%scksum: %s: %s\n", + printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (crc(fd, &val, &len)) { - (void)close(fd); + close(fd); LABEL; - (void)printf("%scksum: %s: %s\n", + printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else { - (void)close(fd); + close(fd); if (s->cksum != val) { LABEL; - (void)printf("%scksum expected %lu found %lu\n", + printf("%scksum expected %lu found %lu\n", tab, s->cksum, val); tab = "\t"; } @@ -216,21 +216,21 @@ typeerr: LABEL; if ((s->flags & F_FLAGS) && s->st_flags != p->fts_statp->st_flags) { LABEL; fflags = flags_to_string(s->st_flags); - (void)printf("%sflags expected \"%s\"", tab, fflags); + printf("%sflags expected \"%s\"", tab, fflags); free(fflags); fflags = flags_to_string(p->fts_statp->st_flags); - (void)printf(" found \"%s\"", fflags); + printf(" found \"%s\"", fflags); free(fflags); if (uflag) if (chflags(p->fts_accpath, s->st_flags)) - (void)printf(" not modified: %s\n", + printf(" not modified: %s\n", strerror(errno)); else - (void)printf(" modified\n"); + printf(" modified\n"); else - (void)printf("\n"); + printf("\n"); tab = "\t"; } #ifdef MD5 @@ -291,7 +291,7 @@ typeerr: LABEL; if (s->flags & F_SLINK && strcmp(cp = rlink(p->fts_accpath), s->slink)) { LABEL; - (void)printf("%slink_ref expected %s found %s\n", + printf("%slink_ref expected %s found %s\n", tab, s->slink, cp); } return (label); @@ -349,7 +349,7 @@ char * rlink(char *name) { static char lbuf[MAXPATHLEN]; - register int len; + int len; if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1) err(1, "line %d: %s", lineno, name); diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index 757d899067..ba3534bfbb 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -32,7 +32,7 @@ * * @(#)create.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/create.c,v 1.18.2.3 2001/01/12 19:17:18 phk Exp $ - * $DragonFly: src/usr.sbin/mtree/create.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/create.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -85,15 +85,15 @@ static void statf(int, FTSENT *); void cwalk(void) { - register FTS *t; - register FTSENT *p; + FTS *t; + FTSENT *p; time_t clock; char *argv[2], host[MAXHOSTNAMELEN]; int indent = 0; - (void)time(&clock); - (void)gethostname(host, sizeof(host)); - (void)printf( + time(&clock); + gethostname(host, sizeof(host)); + printf( "#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s", getlogin(), host, fullpath, ctime(&clock)); @@ -111,18 +111,18 @@ cwalk(void) switch(p->fts_info) { case FTS_D: if (!dflag) - (void)printf("\n"); + printf("\n"); if (!nflag) - (void)printf("# %s\n", p->fts_path); + printf("# %s\n", p->fts_path); statd(t, p, &uid, &gid, &mode, &flags); statf(indent, p); break; case FTS_DP: if (!nflag && (p->fts_level > 0)) - (void)printf("%*s# %s\n", indent, "", p->fts_path); - (void)printf("%*s..\n", indent, ""); + printf("%*s# %s\n", indent, "", p->fts_path); + printf("%*s..\n", indent, ""); if (!dflag) - (void)printf("\n"); + printf("\n"); break; case FTS_DNR: case FTS_ERR: @@ -136,7 +136,7 @@ cwalk(void) } } - (void)fts_close(t); + fts_close(t); if (sflag && keys & F_CKSUM) warnx("%s checksum: %lu", fullpath, crc_total); } @@ -210,7 +210,7 @@ statf(int indent, FTSENT *p) if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) err(1, "line %d: %s", lineno, p->fts_accpath); - (void)close(fd); + close(fd); output(indent, &offset, "cksum=%lu", val); } #ifdef MD5 @@ -257,7 +257,7 @@ statf(int indent, FTSENT *p) output(indent, &offset, "flags=%s", fflags); free(fflags); } - (void)putchar('\n'); + putchar('\n'); } #define MAXGID 5000 @@ -270,11 +270,11 @@ static int statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *pflags) { - register FTSENT *p; - register gid_t sgid; - register uid_t suid; - register mode_t smode; - register u_long sflags; + FTSENT *p; + gid_t sgid; + uid_t suid; + mode_t smode; + u_long sflags; struct group *gr; struct passwd *pw; gid_t savegid = *pgid; @@ -343,39 +343,39 @@ statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, (first)) { first = 0; if (dflag) - (void)printf("/set type=dir"); + printf("/set type=dir"); else - (void)printf("/set type=file"); + printf("/set type=file"); if (keys & F_UNAME) { if ((pw = getpwuid(saveuid)) != NULL) - (void)printf(" uname=%s", pw->pw_name); + printf(" uname=%s", pw->pw_name); else errx(1, "line %d: could not get uname for uid=%u", lineno, saveuid); } if (keys & F_UID) - (void)printf(" uid=%lu", (u_long)saveuid); + printf(" uid=%lu", (u_long)saveuid); if (keys & F_GNAME) { if ((gr = getgrgid(savegid)) != NULL) - (void)printf(" gname=%s", gr->gr_name); + printf(" gname=%s", gr->gr_name); else errx(1, "line %d: could not get gname for gid=%u", lineno, savegid); } if (keys & F_GID) - (void)printf(" gid=%lu", (u_long)savegid); + printf(" gid=%lu", (u_long)savegid); if (keys & F_MODE) - (void)printf(" mode=%#o", savemode); + printf(" mode=%#o", savemode); if (keys & F_NLINK) - (void)printf(" nlink=1"); + printf(" nlink=1"); if (keys & F_FLAGS) { fflags = flags_to_string(saveflags); - (void)printf(" flags=%s", fflags); + printf(" flags=%s", fflags); free(fflags); } - (void)printf("\n"); + printf("\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; @@ -387,6 +387,7 @@ statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, static int dsort(const FTSENT **a, const FTSENT **b) { + if (S_ISDIR((*a)->fts_statp->st_mode)) { if (!S_ISDIR((*b)->fts_statp->st_mode)) return (1); @@ -402,11 +403,11 @@ output(int indent, int *offset, const char *fmt, ...) char buf[1024]; va_start(ap, fmt); - (void)vsnprintf(buf, sizeof(buf), fmt, ap); + vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (*offset + strlen(buf) > MAXLINELEN - 3) { - (void)printf(" \\\n%*s", INDENTNAMELEN + indent, ""); + printf(" \\\n%*s", INDENTNAMELEN + indent, ""); *offset = INDENTNAMELEN + indent; } *offset += printf(" %s", buf) + 1; diff --git a/usr.sbin/mtree/excludes.c b/usr.sbin/mtree/excludes.c index 9df64fb97d..13e540a5cc 100644 --- a/usr.sbin/mtree/excludes.c +++ b/usr.sbin/mtree/excludes.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.sbin/mtree/excludes.c,v 1.1.2.4 2001/01/12 19:17:18 phk Exp $ - * $DragonFly: src/usr.sbin/mtree/excludes.c,v 1.2 2003/06/17 04:29:57 dillon Exp $ + * $DragonFly: src/usr.sbin/mtree/excludes.c,v 1.3 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -57,6 +57,7 @@ static LIST_HEAD(, exclude) excludes; void init_excludes(void) { + LIST_INIT(&excludes); } diff --git a/usr.sbin/mtree/misc.c b/usr.sbin/mtree/misc.c index 03453b4b12..515ae0c587 100644 --- a/usr.sbin/mtree/misc.c +++ b/usr.sbin/mtree/misc.c @@ -32,7 +32,7 @@ * * @(#)misc.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/misc.c,v 1.8.2.1 2000/06/28 02:33:17 joe Exp $ - * $DragonFly: src/usr.sbin/mtree/misc.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/misc.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -101,6 +101,7 @@ parsekey(char *name, int *needvaluep) int keycompare(const void *a, const void *b) { + return (strcmp(((KEY *)a)->name, ((KEY *)b)->name)); } diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c index c1e7401355..740ca29bfd 100644 --- a/usr.sbin/mtree/mtree.c +++ b/usr.sbin/mtree/mtree.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1989, 1990, 1993 The Regents of the University of California. All rights reserved. * @(#)mtree.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/mtree.c,v 1.8.2.3 2003/05/07 17:55:17 tobez Exp $ - * $DragonFly: src/usr.sbin/mtree/mtree.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/mtree.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -56,7 +56,7 @@ char fullpath[MAXPATHLEN]; static void usage(void); int -main(int argc, char **argv) +main(int argc, char *argv[]) { int ch; char *dir, *p; @@ -163,7 +163,8 @@ main(int argc, char **argv) static void usage(void) { - (void)fprintf(stderr, + + fprintf(stderr, "usage: mtree [-LPUcdeinqrux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n" "\t[-X excludes]\n"); exit(1); diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index c8c3fc78b1..11b8f13320 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -32,7 +32,7 @@ * * @(#)spec.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/spec.c,v 1.13.2.1 2000/06/28 02:33:17 joe Exp $ - * $DragonFly: src/usr.sbin/mtree/spec.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/spec.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -57,8 +57,8 @@ static void unset(char *, NODE *); NODE * spec(void) { - register NODE *centry, *last; - register char *p; + NODE *centry, *last; + char *p; NODE ginfo, *root; int c_cur, c_next; char buf[2048]; @@ -93,7 +93,7 @@ spec(void) continue; #ifdef DEBUG - (void)fprintf(stderr, "line %d: {%s}\n", lineno, p); + fprintf(stderr, "line %d: {%s}\n", lineno, p); #endif if (c_cur) { set(p, centry); @@ -168,7 +168,7 @@ noparent: errx(1, "line %d: no parent node", lineno); static void set(char *t, NODE *ip) { - register int type; + int type; char *kw, *val = NULL; struct group *gr; struct passwd *pw; @@ -306,9 +306,9 @@ set(char *t, NODE *ip) } static void -unset(char *t, register NODE *ip) +unset(char *t, NODE *ip) { - register char *p; + char *p; while ((p = strtok(t, "\n\t "))) ip->flags &= ~parsekey(p, NULL); diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c index 8bbb8add34..5e0dfe911a 100644 --- a/usr.sbin/mtree/verify.c +++ b/usr.sbin/mtree/verify.c @@ -32,7 +32,7 @@ * * @(#)verify.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/mtree/verify.c,v 1.10.2.2 2001/01/12 19:17:18 phk Exp $ - * $DragonFly: src/usr.sbin/mtree/verify.c,v 1.4 2003/11/22 11:38:13 eirikn Exp $ + * $DragonFly: src/usr.sbin/mtree/verify.c,v 1.5 2004/03/15 16:24:22 dillon Exp $ */ #include @@ -73,9 +73,9 @@ verify(void) static int vwalk(void) { - register FTS *t; - register FTSENT *p; - register NODE *ep, *level; + FTS *t; + FTSENT *p; + NODE *ep, *level; int specdepth, rval; char *argv[2]; @@ -122,7 +122,7 @@ vwalk(void) compare(ep->name, ep, p)) rval = MISMATCHEXIT; if (ep->flags & F_IGN) - (void)fts_set(t, p, FTS_SKIP); + fts_set(t, p, FTS_SKIP); else if (ep->child && ep->type == F_DIR && p->fts_info == FTS_D) { level = ep->child; @@ -135,36 +135,36 @@ vwalk(void) continue; extra: if (!eflag) { - (void)printf("%s extra", RP(p)); + printf("%s extra", RP(p)); if (rflag) { if ((S_ISDIR(p->fts_statp->st_mode) ? rmdir : unlink)(p->fts_accpath)) { - (void)printf(", not removed: %s", + printf(", not removed: %s", strerror(errno)); } else - (void)printf(", removed"); + printf(", removed"); } - (void)putchar('\n'); + putchar('\n'); } - (void)fts_set(t, p, FTS_SKIP); + fts_set(t, p, FTS_SKIP); } - (void)fts_close(t); + fts_close(t); if (sflag) warnx("%s checksum: %lu", fullpath, crc_total); return (rval); } static void -miss(register NODE *p, register char *tail) +miss(NODE *p, char *tail) { - register int create; - register char *tp; + int create; + char *tp; const char *type; for (; p; p = p->next) { if (p->type != F_DIR && (dflag || p->flags & F_VISIT)) continue; - (void)strcpy(tail, p->name); + strcpy(tail, p->name); if (!(p->flags & F_VISIT)) { /* Don't print missing message if file exists as a symbolic link and the -q flag is set. */ @@ -173,7 +173,7 @@ miss(register NODE *p, register char *tail) if (qflag && stat(path, &statbuf) == 0) p->flags |= F_VISIT; else - (void)printf("%s missing", path); + printf("%s missing", path); } if (p->type != F_DIR && p->type != F_LINK) { putchar('\n'); @@ -187,31 +187,31 @@ miss(register NODE *p, register char *tail) type = "directory"; if (!(p->flags & F_VISIT) && uflag) { if (!(p->flags & (F_UID | F_UNAME))) - (void)printf(" (%s not created: user not specified)", type); + printf(" (%s not created: user not specified)", type); else if (!(p->flags & (F_GID | F_GNAME))) - (void)printf(" (%s not created: group not specified)", type); + printf(" (%s not created: group not specified)", type); else if (p->type == F_LINK) { if (symlink(p->slink, path)) - (void)printf(" (symlink not created: %s)\n", + printf(" (symlink not created: %s)\n", strerror(errno)); else - (void)printf(" (created)\n"); + printf(" (created)\n"); if (lchown(path, p->st_uid, p->st_gid)) - (void)printf("%s: user/group not modified: %s\n", + printf("%s: user/group not modified: %s\n", path, strerror(errno)); continue; } else if (!(p->flags & F_MODE)) - (void)printf(" (directory not created: mode not specified)"); + printf(" (directory not created: mode not specified)"); else if (mkdir(path, S_IRWXU)) - (void)printf(" (directory not created: %s)", + printf(" (directory not created: %s)", strerror(errno)); else { create = 1; - (void)printf(" (created)"); + printf(" (created)"); } } if (!(p->flags & F_VISIT)) - (void)putchar('\n'); + putchar('\n'); for (tp = tail; *tp; ++tp); *tp = '/'; @@ -221,18 +221,18 @@ miss(register NODE *p, register char *tail) if (!create) continue; if (chown(path, p->st_uid, p->st_gid)) { - (void)printf("%s: user/group/mode not modified: %s\n", + printf("%s: user/group/mode not modified: %s\n", path, strerror(errno)); - (void)printf("%s: warning: file mode %snot set\n", path, + printf("%s: warning: file mode %snot set\n", path, (p->flags & F_FLAGS) ? "and file flags " : ""); continue; } if (chmod(path, p->st_mode)) - (void)printf("%s: permissions not set: %s\n", + printf("%s: permissions not set: %s\n", path, strerror(errno)); if ((p->flags & F_FLAGS) && p->st_flags && chflags(path, p->st_flags)) - (void)printf("%s: file flags not set: %s\n", + printf("%s: file flags not set: %s\n", path, strerror(errno)); } } -- 2.41.0