quot: Use getopt(3) and show usage() if no arguments

Also update the man page and usage to be a little more accurate with the
-a flag.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/983
This commit is contained in:
Ricardo Branco
2024-02-02 17:12:22 -07:00
committed by Warner Losh
parent 8e05c2373e
commit 752a340419
2 changed files with 36 additions and 31 deletions
+2 -2
View File
@@ -35,8 +35,8 @@
.Nd display disk space occupied by each user .Nd display disk space occupied by each user
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl acfhknv .Op Fl cfhknv
.Op Ar filesystem ... .Op Fl a | Ar filesystem ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
+16 -11
View File
@@ -526,9 +526,9 @@ static void
usage(void) usage(void)
{ {
#ifdef COMPAT #ifdef COMPAT
fprintf(stderr,"usage: quot [-nfcvha] [filesystem ...]\n"); fprintf(stderr, "usage: quot [-cfhnv] [-a | filesystem ...]\n");
#else /* COMPAT */ #else /* COMPAT */
fprintf(stderr,"usage: quot [-acfhknv] [filesystem ...]\n"); fprintf(stderr, "usage: quot [-cfhknv] [-a | filesystem ...]\n");
#endif /* COMPAT */ #endif /* COMPAT */
exit(1); exit(1);
} }
@@ -575,23 +575,20 @@ main(int argc, char *argv[])
struct statfs *mp; struct statfs *mp;
struct fstab *fs; struct fstab *fs;
int cnt; int cnt;
int ch;
func = douser; func = douser;
#ifndef COMPAT #ifndef COMPAT
header = getbsize(&headerlen,&blocksize); header = getbsize(&headerlen,&blocksize);
#endif #endif
while (--argc > 0 && **++argv == '-') { while ((ch = getopt(argc, argv, "acfhknv")) != -1) {
while (*++*argv) { switch (ch) {
switch (**argv) { case 'a':
case 'n': all = 1;
func = donames;
break; break;
case 'c': case 'c':
func = dofsizes; func = dofsizes;
break; break;
case 'a':
all = 1;
break;
case 'f': case 'f':
count = 1; count = 1;
break; break;
@@ -603,6 +600,9 @@ main(int argc, char *argv[])
blocksize = 1024; blocksize = 1024;
break; break;
#endif /* COMPAT */ #endif /* COMPAT */
case 'n':
func = donames;
break;
case 'v': case 'v':
unused = 1; unused = 1;
break; break;
@@ -610,7 +610,12 @@ main(int argc, char *argv[])
usage(); usage();
} }
} }
} argc -= optind;
argv += optind;
if ((argc == 0 && !all) || (all && argc))
usage();
if (all) { if (all) {
cnt = getmntinfo(&mp,MNT_NOWAIT); cnt = getmntinfo(&mp,MNT_NOWAIT);
for (; --cnt >= 0; mp++) { for (; --cnt >= 0; mp++) {