add 1994 copyright
[unix-history] / usr / src / bin / ls / ls.c
index cd007d8..9628f7c 100644 (file)
@@ -1,6 +1,6 @@
 /*
 /*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
  *
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
 
 #ifndef lint
 static char copyright[] =
 
 #ifndef lint
 static char copyright[] =
-"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
+"@(#) Copyright (c) 1989, 1993, 1994\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.73 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       8.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+
 #include <dirent.h>
 #include <dirent.h>
-#include <unistd.h>
+#include <err.h>
+#include <errno.h>
 #include <fts.h>
 #include <fts.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
-#include <stdio.h>
+#include <unistd.h>
+
 #include "ls.h"
 #include "extern.h"
 
 #include "ls.h"
 #include "extern.h"
 
-char   *getbsize __P((char *, int *, long *));
-
 static void     display __P((FTSENT *, FTSENT *));
 static int      mastercmp __P((const FTSENT **, const FTSENT **));
 static void     traverse __P((int, char **, int));
 static void     display __P((FTSENT *, FTSENT *));
 static int      mastercmp __P((const FTSENT **, const FTSENT **));
 static void     traverse __P((int, char **, int));
@@ -78,7 +79,7 @@ main(argc, argv)
        if (isatty(STDOUT_FILENO)) {
                if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1 ||
                    !win.ws_col) {
        if (isatty(STDOUT_FILENO)) {
                if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1 ||
                    !win.ws_col) {
-                       if (p = getenv("COLUMNS"))
+                       if ((p = getenv("COLUMNS")) != NULL)
                                termwidth = atoi(p);
                }
                else
                                termwidth = atoi(p);
                }
                else
@@ -192,7 +193,7 @@ main(argc, argv)
 
        /* If -l or -s, figure out block size. */
        if (f_longform || f_size) {
 
        /* If -l or -s, figure out block size. */
        if (f_longform || f_size) {
-               (void)getbsize("ls", &notused, &blocksize);
+               (void)getbsize(&notused, &blocksize);
                blocksize /= 512;
        }
 
                blocksize /= 512;
        }
 
@@ -245,13 +246,13 @@ traverse(argc, argv, options)
        int argc, options;
        char *argv[];
 {
        int argc, options;
        char *argv[];
 {
-       register FTS *ftsp;
-       register FTSENT *p, *chp;
+       FTS *ftsp;
+       FTSENT *p, *chp;
        int ch_options;
 
        if ((ftsp =
            fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
        int ch_options;
 
        if ((ftsp =
            fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
-               err(1, "%s", strerror(errno));
+               err(1, NULL);
 
        display(NULL, fts_children(ftsp, 0));
        if (f_listdir)
 
        display(NULL, fts_children(ftsp, 0));
        if (f_listdir)
@@ -263,15 +264,14 @@ traverse(argc, argv, options)
         */
        ch_options = !f_recursive && options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
 
         */
        ch_options = !f_recursive && options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
 
-       while (p = fts_read(ftsp))
-               switch(p->fts_info) {
+       while ((p = fts_read(ftsp)) != NULL)
+               switch (p->fts_info) {
                case FTS_DC:
                case FTS_DC:
-                       err(0, "%s: directory causes a cycle", p->fts_name);
+                       warnx("%s: directory causes a cycle", p->fts_name);
                        break;
                case FTS_DNR:
                case FTS_ERR:
                        break;
                case FTS_DNR:
                case FTS_ERR:
-                       err(0, "%s: %s",
-                           p->fts_name, strerror(p->fts_errno));
+                       warnx("%s: %s", p->fts_name, strerror(p->fts_errno));
                        break;
                case FTS_D:
                        if (p->fts_level != FTS_ROOTLEVEL &&
                        break;
                case FTS_D:
                        if (p->fts_level != FTS_ROOTLEVEL &&
@@ -297,7 +297,8 @@ traverse(argc, argv, options)
                                (void)fts_set(ftsp, p, FTS_SKIP);
                        break;
                }
                                (void)fts_set(ftsp, p, FTS_SKIP);
                        break;
                }
-       (void)fts_close(ftsp);
+       if (errno)
+               err(1, "fts_read");
 }
 
 /*
 }
 
 /*
@@ -307,15 +308,14 @@ traverse(argc, argv, options)
  */
 static void
 display(p, list)
  */
 static void
 display(p, list)
-       register FTSENT *p;
-       FTSENT *list;
+       FTSENT *p, *list;
 {
 {
-       register FTSENT *cur;
        struct stat *sp;
        DISPLAY d;
        struct stat *sp;
        DISPLAY d;
+       FTSENT *cur;
        NAMES *np;
        NAMES *np;
-       u_long btotal, maxblock, maxinode, maxlen, maxnlink;
        u_quad_t maxsize;
        u_quad_t maxsize;
+       u_long btotal, maxblock, maxinode, maxlen, maxnlink;
        int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
        int entries, needstats;
        char *user, *group, *flags, buf[20];    /* 32 bits == 10 digits */
        int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
        int entries, needstats;
        char *user, *group, *flags, buf[20];    /* 32 bits == 10 digits */
@@ -338,7 +338,7 @@ display(p, list)
        maxsize = 0;
        for (cur = list, entries = 0; cur; cur = cur->fts_link) {
                if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
        maxsize = 0;
        for (cur = list, entries = 0; cur; cur = cur->fts_link) {
                if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
-                       err(0, "%s: %s",
+                       warnx("%s: %s",
                            cur->fts_name, strerror(cur->fts_errno));
                        cur->fts_number = NO_PRINT;
                        continue;
                            cur->fts_name, strerror(cur->fts_errno));
                        cur->fts_number = NO_PRINT;
                        continue;
@@ -394,7 +394,7 @@ display(p, list)
 
                                if ((np = malloc(sizeof(NAMES) +
                                    ulen + glen + flen + 3)) == NULL)
 
                                if ((np = malloc(sizeof(NAMES) +
                                    ulen + glen + flen + 3)) == NULL)
-                                       err(1, "%s", strerror(errno));
+                                       err(1, NULL);
 
                                np->user = &np->data[0];
                                (void)strcpy(np->user, user);
 
                                np->user = &np->data[0];
                                (void)strcpy(np->user, user);
@@ -455,7 +455,7 @@ static int
 mastercmp(a, b)
        const FTSENT **a, **b;
 {
 mastercmp(a, b)
        const FTSENT **a, **b;
 {
-       register int a_info, b_info;
+       int a_info, b_info;
 
        a_info = (*a)->fts_info;
        if (a_info == FTS_ERR)
 
        a_info = (*a)->fts_info;
        if (a_info == FTS_ERR)