simplify dev_mkdb: -) no need for getopt() since there are no possible options, just check if argc < 1 -) usage() only used once: move it to the single point of failure for user input -) bzero => memset, bcopy => memcpy -) no brackets for return according to style(9)
no functional change except that # dev_mkdb -a dev_mkdb: unknown option -- a usage: dev_mkdb becomes: # ./dev_mkdb -a usage: dev_mkdb Clemens Index: usr.sbin/dev_mkdb/dev_mkdb.c =================================================================== RCS file: /cvs/src/usr.sbin/dev_mkdb/dev_mkdb.c,v retrieving revision 1.16 diff -u -p -r1.16 dev_mkdb.c --- usr.sbin/dev_mkdb/dev_mkdb.c 9 Aug 2018 14:30:28 -0000 1.16 +++ usr.sbin/dev_mkdb/dev_mkdb.c 19 Sep 2018 18:33:33 -0000 @@ -42,8 +42,6 @@ #include <string.h> #include <unistd.h> -void usage(void); - int main(int argc, char *argv[]) { @@ -64,17 +62,10 @@ main(int argc, char *argv[]) if (pledge("stdio rpath wpath cpath flock", NULL) == -1) err(1, "pledge"); - while ((ch = getopt(argc, argv, "")) != -1) - switch(ch) { - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc > 0) - usage(); + if (argc > 1) { + (void)fprintf(stderr, "usage: dev_mkdb\n"); + exit(1); + } if (chdir(_PATH_DEV)) err(1, "%s", _PATH_DEV); @@ -83,7 +74,7 @@ main(int argc, char *argv[]) (void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN); (void)snprintf(dbname, sizeof(dbname), "%sdev.db", _PATH_VARRUN); - bzero(&info, sizeof(info)); + memset(&info, 0, sizeof(info)); info.bsize = 8192; db = dbopen(dbtmp, O_CREAT|O_EXLOCK|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, &info); @@ -96,7 +87,7 @@ main(int argc, char *argv[]) * that the structure may contain padding, so we have to clear it * out here. */ - bzero(&bkey, sizeof(bkey)); + memset(&bkey, 0, sizeof(bkey)); key.data = &bkey; key.size = sizeof(bkey); data.data = buf; @@ -119,7 +110,7 @@ main(int argc, char *argv[]) * Create the data; nul terminate the name so caller doesn't * have to. */ - bcopy(dp->d_name, buf, dp->d_namlen); + memcpy(buf, dp->d_name, dp->d_namlen); buf[dp->d_namlen] = '\0'; data.size = dp->d_namlen + 1; if ((db->put)(db, &key, &data, 0)) @@ -129,13 +120,5 @@ main(int argc, char *argv[]) if (rename(dbtmp, dbname)) err(1, "rename %s to %s", dbtmp, dbname); - return (0); -} - -void -usage(void) -{ - - (void)fprintf(stderr, "usage: dev_mkdb\n"); - exit(1); + return 0; }