Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/quot KNF



details:   https://anonhg.NetBSD.org/src/rev/73d2f993f1f6
branches:  trunk
changeset: 762979:73d2f993f1f6
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 06 23:41:47 2011 +0000

description:
KNF

diffstat:

 usr.sbin/quot/Makefile |    4 +-
 usr.sbin/quot/quot.c   |  143 ++++++++++++++++++++----------------------------
 2 files changed, 61 insertions(+), 86 deletions(-)

diffs (truncated from 343 to 300 lines):

diff -r 3425ecebde4c -r 73d2f993f1f6 usr.sbin/quot/Makefile
--- a/usr.sbin/quot/Makefile    Sun Mar 06 23:26:05 2011 +0000
+++ b/usr.sbin/quot/Makefile    Sun Mar 06 23:41:47 2011 +0000
@@ -1,6 +1,6 @@
-#      $NetBSD: Makefile,v 1.5 2009/04/22 15:23:07 lukem Exp $
+#      $NetBSD: Makefile,v 1.6 2011/03/06 23:41:47 christos Exp $
 
-WARNS?=        3       # XXX -Wsign-compare
+WARNS?=        4
 
 PROG=  quot
 MAN=   quot.8
diff -r 3425ecebde4c -r 73d2f993f1f6 usr.sbin/quot/quot.c
--- a/usr.sbin/quot/quot.c      Sun Mar 06 23:26:05 2011 +0000
+++ b/usr.sbin/quot/quot.c      Sun Mar 06 23:41:47 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quot.c,v 1.28 2009/04/18 08:17:23 lukem Exp $  */
+/*     $NetBSD: quot.c,v 1.29 2011/03/06 23:41:47 christos Exp $       */
 
 /*
  * Copyright (C) 1991, 1994 Wolfgang Solfrank.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: quot.c,v 1.28 2009/04/18 08:17:23 lukem Exp $");
+__RCSID("$NetBSD: quot.c,v 1.29 2011/03/06 23:41:47 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -55,7 +55,7 @@
 static char estimate;
 static char count;
 static char unused;
-static void (*func) __P((int, struct fs *, char *));
+static void (*func)(int, struct fs *, const char *);
 static long blocksize;
 static char *header;
 
@@ -87,29 +87,25 @@
        (dp)->dp1.di_##field : (dp)->dp2.di_##field)
 
 
-static int             cmpusers __P((const void *, const void *));
-static void            dofsizes __P((int, struct fs *, char *));
-static void            donames __P((int, struct fs *, char *));
-static void            douser __P((int, struct fs *, char *));
-static union dinode  *get_inode __P((int, struct fs*, ino_t));
-static void            ffs_oldfscompat __P((struct fs *));
-static void            initfsizes __P((void));
-static void            inituser __P((void));
-static int             isfree __P((struct fs *, union dinode *));
-       int             main __P((int, char **));
-       void            quot __P((char *, char *));
-static void            usage __P((void));
-static struct user    *user __P((uid_t));
-static void            uses __P((uid_t, daddr_t, time_t));
-static void            usrrehash __P((void));
-static int             virtualblocks __P((struct fs *, union dinode *));
+static int             cmpusers(const void *, const void *);
+static void            dofsizes(int, struct fs *, const char *);
+static void            donames(int, struct fs *, const char *);
+static void            douser(int, struct fs *, const char *);
+static union dinode  *get_inode(int, struct fs *, ino_t);
+static void            ffs_oldfscompat(struct fs *);
+static void            initfsizes(void);
+static void            inituser(void);
+static int             isfree(struct fs *, union dinode *);
+static void            quot(const char *, const char *);
+static void            usage(void) __attribute__((__noreturn__));
+static struct user    *user(uid_t);
+static void            uses(uid_t, daddr_t, time_t);
+static void            usrrehash(void);
+static int             virtualblocks(struct fs *, union dinode *);
 
 
 static union dinode *
-get_inode(fd, super, ino)
-       int fd;
-       struct fs *super;
-       ino_t ino;
+get_inode(int fd, struct fs *super, ino_t ino)
 {
        static char *ipbuf;
        static ino_t last;
@@ -130,7 +126,7 @@
                if (lseek(fd,
                    (off_t)ino_to_fsba(super, last) << super->fs_fshift,
                    0) < 0 ||
-                   read(fd, ipbuf, INOSZ(super)) != INOSZ(super))
+                   read(fd, ipbuf, INOSZ(super)) != (ssize_t)INOSZ(super))
                        errx(1, "read inodes");
        }
 
@@ -142,15 +138,13 @@
 }
 
 #ifdef COMPAT
-#define        actualblocks(fs, dp)    (DIP(fs, dp, blocks) / 2)
+#define        actualblocks(fs, dp)    (int)(DIP(fs, dp, blocks) / 2)
 #else
-#define        actualblocks(fs, dp)    (DIP(fs, dp, blocks))
+#define        actualblocks(fs, dp)    (int)(DIP(fs, dp, blocks))
 #endif
 
 static int
-virtualblocks(super, dp)
-       struct fs *super;
-       union dinode *dp;
+virtualblocks(struct fs *super, union dinode *dp)
 {
        off_t nblk, sz;
        
@@ -213,16 +207,15 @@
 static int nusers;
 
 static void
-inituser()
+inituser(void)
 {
        int i;
        struct user *usr;
        
        if (!nusers) {
                nusers = 8;
-               if (!(users =
-                   (struct user *)calloc(nusers, sizeof(struct user))))
-                       errx(1, "allocate users");
+               if (!(users = calloc(nusers, sizeof(*users))))
+                       err(1, "allocate users");
        } else {
                for (usr = users, i = nusers; --i >= 0; usr++) {
                        usr->space = usr->spc30 = usr->spc60 = usr->spc90 = 0;
@@ -232,7 +225,7 @@
 }
 
 static void
-usrrehash()
+usrrehash(void)
 {
        int i;
        struct user *usr, *usrn;
@@ -240,8 +233,8 @@
        
        svusr = users;
        nusers <<= 1;
-       if (!(users = (struct user *)calloc(nusers, sizeof(struct user))))
-               errx(1, "allocate users");
+       if (!(users = calloc(nusers, sizeof(*users))))
+               err(1, "allocate users");
        for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) {
                for (usrn = users + (usr->uid&(nusers - 1));
                     usrn->name;
@@ -254,31 +247,24 @@
 }
 
 static struct user *
-user(uid)
-       uid_t uid;
+user(uid_t uid)
 {
        struct user *usr;
        int i;
        struct passwd *pwd;
        
-       while (1) {
-               for (usr = users + (uid&(nusers - 1)), i = nusers;
+       for (;;) {
+               for (usr = users + (uid & (nusers - 1)), i = nusers;
                     --i >= 0;
                     usr--) {
                        if (!usr->name) {
                                usr->uid = uid;
                                
-                               if (!(pwd = getpwuid(uid))) {
-                                       if ((usr->name =
-                                           (char *)malloc(7)) != NULL)
-                                               sprintf(usr->name, "#%d", uid);
-                               } else {
-                                       if ((usr->name =
-                                           (char *)malloc(
-                                               strlen(pwd->pw_name) + 1))
-                                           != NULL)
-                                               strcpy(usr->name, pwd->pw_name);
-                               }
+                               if (!(pwd = getpwuid(uid)))
+                                       asprintf(&usr->name, "#%u", uid);
+                               else
+                                       asprintf(&usr->name, "%s",
+                                           pwd->pw_name);
                                if (!usr->name)
                                        errx(1, "allocate users");
                                return usr;
@@ -353,10 +339,7 @@
 }
 
 static void
-dofsizes(fd, super, name)
-       int fd;
-       struct fs *super;
-       char *name;
+dofsizes(int fd, struct fs *super, const char *name)
 {
        ino_t inode, maxino;
        union dinode *dp;
@@ -366,8 +349,8 @@
        
        maxino = super->fs_ncg * super->fs_ipg - 1;
 #ifdef COMPAT
-       if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes))))
-               errx(1, "alloc fsize structure");
+       if (!(fsizes = malloc(sizeof(*fsizes))))
+               err(1, "alloc fsize structure");
 #endif /* COMPAT */
        for (inode = 0; inode < maxino; inode++) {
                errno = 0;
@@ -397,9 +380,8 @@
                                        break;
                        }
                        if (!fp || ksz < fp->fsz_first) {
-                               if (!(fp = (struct fsizes *)
-                                     malloc(sizeof(struct fsizes))))
-                                       errx(1, "alloc fsize structure");
+                               if (!(fp = malloc(sizeof(*fp))))
+                                       err(1, "alloc fsize structure");
                                fp->fsz_next = *fsp;
                                *fsp = fp;
                                fp->fsz_first = (ksz / FSZCNT) * FSZCNT;
@@ -428,10 +410,7 @@
 }
 
 static void
-douser(fd, super, name)
-       int fd;
-       struct fs *super;
-       char *name;
+douser(int fd, struct fs *super, const char *name)
 {
        ino_t inode, maxino;
        struct user *usr, *usrs;
@@ -449,9 +428,9 @@
                else if (errno)
                        errx(1, "%s", name);
        }
-       if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user))))
+       if (!(usrs = calloc(nusers, sizeof(*usrs))))
                errx(1, "allocate users");
-       memmove(usrs, users, nusers * sizeof(struct user));
+       memmove(usrs, users, nusers * sizeof(*usrs));
        sortusers(usrs);
        for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) {
                printf("%5lld", SIZE(usr->space));
@@ -468,10 +447,7 @@
 }
 
 static void
-donames(fd, super, name)
-       int fd;
-       struct fs *super;
-       char *name;
+donames(int fd, struct fs *super, const char *name)
 {
        int c;
        ino_t inode, inode1;
@@ -512,7 +488,8 @@
                        if (errno)
                                errx(1, "%s", name);
                        /* skip this line */
-                       while ((c = getchar()) != EOF && c != '\n');
+                       while ((c = getchar()) != EOF && c != '\n')
+                               continue;
                }
                if (c == EOF)
                        break;
@@ -520,12 +497,13 @@
 }
 
 static void
-usage()
+usage(void)
 {
+       const char *p = getprogname();
 #ifdef COMPAT
-       fprintf(stderr, "usage: quot [-nfcvha] [filesystem ...]\n");
+       fprintf(stderr, "Usage: %s [-nfcvha] [<filesystem> ...]\n", p);
 #else  /* COMPAT */
-       fprintf(stderr, "usage: quot [ -acfhknv ] [ filesystem ... ]\n");
+       fprintf(stderr, "Usage: %s [ -acfhknv ] [<filesystem> ... ]\n", p);
 #endif /* COMPAT */
        exit(1);
 }
@@ -535,8 +513,7 @@
  * Stolen from <sys/lib/libsa/ufs.c>
  */
 static void
-ffs_oldfscompat(fs)
-       struct fs *fs;
+ffs_oldfscompat(struct fs *fs)
 {
        int i;



Home | Main Index | Thread Index | Old Index