cleanups, add manual page
[unix-history] / usr / src / usr.bin / quota / quota.c
index 95c988e..2a05a0e 100644 (file)
@@ -1,18 +1,29 @@
 /*
  * Copyright (c) 1980 Regents of the University of California.
 /*
  * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)quota.c    5.2 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)quota.c    5.6 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Disk quota reporting program.
 
 /*
  * Disk quota reporting program.
@@ -40,7 +51,7 @@ main(argc, argv)
        register char *cp;
        extern int errno;
 
        register char *cp;
        extern int errno;
 
-       if (quota(Q_SYNC, 0, 0, 0) < 0 && errno == EINVAL) {
+       if (quota(Q_SYNC, 0, 0, (caddr_t)0) < 0 && errno == EINVAL) {
                fprintf(stderr, "There are no quotas on this system\n");
                exit(0);
        }
                fprintf(stderr, "There are no quotas on this system\n");
                exit(0);
        }
@@ -106,9 +117,8 @@ showquotas(uid, name)
        int uid;
        char *name;
 {
        int uid;
        char *name;
 {
-       register char c, *p;
        register struct fstab *fs;
        register struct fstab *fs;
-       register char *msgi = (char *)0, *msgb = (char *)0;
+       register char *msgi, *msgb;
        register enab = 1;
        dev_t   fsdev;
        struct  stat statb;
        register enab = 1;
        dev_t   fsdev;
        struct  stat statb;
@@ -122,20 +132,21 @@ showquotas(uid, name)
                return;
        }
        done = 0;
                return;
        }
        done = 0;
-       setfsent();
+       (void) setfsent();
        while (fs = getfsent()) {
                if (stat(fs->fs_spec, &statb) < 0)
                        continue;
        while (fs = getfsent()) {
                if (stat(fs->fs_spec, &statb) < 0)
                        continue;
+               msgi = msgb = (char *) 0;
                fsdev = statb.st_rdev;
                (void) sprintf(qfilename, "%s/%s", fs->fs_file, qfname);
                if (stat(qfilename, &statb) < 0 || statb.st_dev != fsdev)
                        continue;
                fsdev = statb.st_rdev;
                (void) sprintf(qfilename, "%s/%s", fs->fs_file, qfname);
                if (stat(qfilename, &statb) < 0 || statb.st_dev != fsdev)
                        continue;
-               if (quota(Q_GETDLIM, uid, fsdev, &dqblk) != 0) {
+               if (quota(Q_GETDLIM, uid, fsdev, (caddr_t)&dqblk) != 0) {
                        fd = open(qfilename, O_RDONLY);
                        if (fd < 0)
                                continue;
                        fd = open(qfilename, O_RDONLY);
                        if (fd < 0)
                                continue;
-                       lseek(fd, (long)(uid * sizeof (dqblk)), L_SET);
-                       switch (read(fd, &dqblk, sizeof dqblk)) {
+                       (void) lseek(fd, (off_t)(uid * sizeof (dqblk)), L_SET);
+                       switch (read(fd, (char *)&dqblk, sizeof dqblk)) {
                        case 0:                 /* EOF */
                                /*
                                 * Convert implicit 0 quota (EOF)
                        case 0:                 /* EOF */
                                /*
                                 * Convert implicit 0 quota (EOF)
@@ -150,10 +161,10 @@ showquotas(uid, name)
                        default:                /* ERROR */
                                fprintf(stderr, "quota: read error in ");
                                perror(qfilename);
                        default:                /* ERROR */
                                fprintf(stderr, "quota: read error in ");
                                perror(qfilename);
-                               close(fd);
+                               (void) close(fd);
                                continue;
                        }
                                continue;
                        }
-                       close(fd);
+                       (void) close(fd);
                        if (!vflag && dqblk.dqb_isoftlimit == 0 &&
                            dqblk.dqb_bsoftlimit == 0)
                                continue;
                        if (!vflag && dqblk.dqb_isoftlimit == 0 &&
                            dqblk.dqb_bsoftlimit == 0)
                                continue;
@@ -176,11 +187,11 @@ showquotas(uid, name)
                    dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit)
                        msgb = "Over disc quota on %s";
                if (dqblk.dqb_iwarn < MAX_IQ_WARN)
                    dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit)
                        msgb = "Over disc quota on %s";
                if (dqblk.dqb_iwarn < MAX_IQ_WARN)
-                       sprintf(iwarn, "%d", dqblk.dqb_iwarn);
+                       (void) sprintf(iwarn, "%d", dqblk.dqb_iwarn);
                else
                        iwarn[0] = '\0';
                if (dqblk.dqb_bwarn < MAX_DQ_WARN)
                else
                        iwarn[0] = '\0';
                if (dqblk.dqb_bwarn < MAX_DQ_WARN)
-                       sprintf(dwarn, "%d", dqblk.dqb_bwarn);
+                       (void) sprintf(dwarn, "%d", dqblk.dqb_bwarn);
                else
                        dwarn[0] = '\0';
                if (qflag) {
                else
                        dwarn[0] = '\0';
                if (qflag) {
@@ -196,10 +207,10 @@ showquotas(uid, name)
                        heading(uid, name);
                        printf("%10s%8d%c%7d%8d%8s%8d%c%7d%8d%8s\n"
                                , fs->fs_file
                        heading(uid, name);
                        printf("%10s%8d%c%7d%8d%8s%8d%c%7d%8d%8s\n"
                                , fs->fs_file
-                               , (dqblk.dqb_curblocks / btodb(1024)) 
+                               , dbtob(dqblk.dqb_curblocks) / 1024
                                , (msgb == (char *)0) ? ' ' : '*'
                                , (msgb == (char *)0) ? ' ' : '*'
-                               , (dqblk.dqb_bsoftlimit / btodb(1024)) 
-                               , (dqblk.dqb_bhardlimit / btodb(1024)) 
+                               , dbtob(dqblk.dqb_bsoftlimit) / 1024
+                               , dbtob(dqblk.dqb_bhardlimit) / 1024
                                , dwarn
                                , dqblk.dqb_curinodes
                                , (msgi == (char *)0) ? ' ' : '*'
                                , dwarn
                                , dqblk.dqb_curinodes
                                , (msgi == (char *)0) ? ' ' : '*'
@@ -209,10 +220,10 @@ showquotas(uid, name)
                        );
                }
        }
                        );
                }
        }
-       endfsent();
+       (void) endfsent();
        if (!done && !qflag) {
                if (morethanone)
        if (!done && !qflag) {
                if (morethanone)
-                       putchar('\n');
+                       (void) putchar('\n');
                xprintf("Disc quotas for %s (uid %d):", name, uid);
                xprintf("none.");
        }
                xprintf("Disc quotas for %s (uid %d):", name, uid);
                xprintf("none.");
        }
@@ -234,7 +245,7 @@ heading(uid, name)
                xprintf((char *)0);
                return;
        }
                xprintf((char *)0);
                return;
        }
-       putchar('\n');
+       (void) putchar('\n');
        xprintf("Disc quotas for %s (uid %d):", name, uid);
        xprintf((char *)0);
        printf("%10s%8s %7s%8s%8s%8s %7s%8s%8s\n"
        xprintf("Disc quotas for %s (uid %d):", name, uid);
        xprintf((char *)0);
        printf("%10s%8s %7s%8s%8s%8s %7s%8s%8s\n"
@@ -258,17 +269,17 @@ xprintf(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
        static int column;
 
        if (fmt == 0 && column || column >= 40) {
        static int column;
 
        if (fmt == 0 && column || column >= 40) {
-               putchar('\n');
+               (void) putchar('\n');
                column = 0;
        }
        if (fmt == 0)
                return;
                column = 0;
        }
        if (fmt == 0)
                return;
-       sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6);
+       (void) sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6);
        if (column != 0 && strlen(buf) < 39)
                while (column++ < 40)
        if (column != 0 && strlen(buf) < 39)
                while (column++ < 40)
-                       putchar(' ');
+                       (void) putchar(' ');
        else if (column) {
        else if (column) {
-               putchar('\n');
+               (void) putchar('\n');
                column = 0;
        }
        printf("%s", buf);
                column = 0;
        }
        printf("%s", buf);