use strmode(3)
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 20 Apr 1990 07:06:24 +0000 (23:06 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 20 Apr 1990 07:06:24 +0000 (23:06 -0800)
SCCS-vsn: bin/ls/print.c 5.21
SCCS-vsn: usr.bin/find/ls.c 5.2

usr/src/bin/ls/print.c
usr/src/usr.bin/find/ls.c

index d332d96..0088263 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -35,7 +35,9 @@ printlong(stats, num)
        LS *stats;
        register int num;
 {
        LS *stats;
        register int num;
 {
-       char *user_from_uid(), *group_from_gid();
+       extern int errno;
+       static char *modep;
+       char *user_from_uid(), *group_from_gid(), *strerror();
 
        if (f_total)
                (void)printf("total %lu\n", f_kblocks ?
 
        if (f_total)
                (void)printf("total %lu\n", f_kblocks ?
@@ -48,9 +50,12 @@ printlong(stats, num)
                        (void)printf("%4ld ", f_kblocks ?
                            howmany(stats->lstat.st_blocks, 2) :
                            stats->lstat.st_blocks);
                        (void)printf("%4ld ", f_kblocks ?
                            howmany(stats->lstat.st_blocks, 2) :
                            stats->lstat.st_blocks);
-               printperms(stats->lstat.st_mode);
-               (void)printf("%3u %-*s ", stats->lstat.st_nlink, UT_NAMESIZE,
-                   user_from_uid(stats->lstat.st_uid, 0));
+               if (strmode(stats->lstat.st_mode, &modep)) {
+                       (void)fprintf(stderr, "ls: %s.\n", strerror(errno));
+                       exit(1);
+               }
+               (void)printf("%s %3u %-*s ", modep, stats->lstat.st_nlink,
+                   UT_NAMESIZE, user_from_uid(stats->lstat.st_uid, 0));
                if (f_group)
                        (void)printf("%-*s ", UT_NAMESIZE,
                            group_from_gid(stats->lstat.st_gid, 0));
                if (f_group)
                        (void)printf("%-*s ", UT_NAMESIZE,
                            group_from_gid(stats->lstat.st_gid, 0));
@@ -168,113 +173,6 @@ printtime(ftime)
        (void)putchar(' ');
 }
 
        (void)putchar(' ');
 }
 
-/*
- * do the permissions printing, passed the mode
- */
-printperms(mode)
-       mode_t mode;
-{
-        /* print type */
-       switch (mode & S_IFMT) {
-       case S_IFDIR:                   /* directory */
-               (void)putchar('d');
-               break;
-       case S_IFCHR:                   /* character special */
-               (void)putchar('c');
-               break;
-       case S_IFBLK:                   /* block special */
-               (void)putchar('b');
-               break;
-       case S_IFREG:                   /* regular */
-               (void)putchar('-');
-               break;
-       case S_IFLNK:                   /* symbolic link */
-               (void)putchar('l');
-               break;
-       case S_IFSOCK:                  /* socket */
-               (void)putchar('s');
-               break;
-#ifdef S_IFIFO
-       case S_IFIFO:                   /* fifo */
-               (void)putchar('p');
-               break;
-#endif
-       default:                        /* unknown */
-               (void)putchar('?');
-               break;
-       }
-       /* usr */
-       if (mode & S_IRUSR)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWUSR)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXUSR | S_ISUID)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXUSR:
-               (void)putchar('x');
-               break;
-       case S_ISUID:
-               (void)putchar('S');
-               break;
-       case S_IXUSR | S_ISUID:
-               (void)putchar('s');
-               break;
-       }
-       /* group */
-       if (mode & S_IRGRP)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWGRP)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXGRP | S_ISGID)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXGRP:
-               (void)putchar('x');
-               break;
-       case S_ISGID:
-               (void)putchar('S');
-               break;
-       case S_IXGRP | S_ISGID:
-               (void)putchar('s');
-               break;
-       }
-       /* other */
-       if (mode & S_IROTH)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWOTH)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXOTH | S_ISVTX)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXOTH:
-               (void)putchar('x');
-               break;
-       case S_ISVTX:
-               (void)putchar('T');
-               break;
-       case S_IXOTH | S_ISVTX:
-               (void)putchar('t');
-               break;
-       }
-       (void)putchar(' ');
-}
-
 printtype(mode)
        mode_t mode;
 {
 printtype(mode)
        mode_t mode;
 {
index bd00ab6..df32d80 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -35,11 +35,16 @@ printlong(name, accpath, sb)
        char *accpath;                  /* current valid path to filename */
        struct stat *sb;                /* stat buffer */
 {
        char *accpath;                  /* current valid path to filename */
        struct stat *sb;                /* stat buffer */
 {
-       char *user_from_uid(), *group_from_gid();
+       extern int errno;
+       static char *modep;
+       char *user_from_uid(), *group_from_gid(), *strerror();
 
        (void)printf("%6lu %4ld ", sb->st_ino, sb->st_blocks);
 
        (void)printf("%6lu %4ld ", sb->st_ino, sb->st_blocks);
-       printperms(sb->st_mode);
-       (void)printf("%3u %-*s %-*s ", sb->st_nlink, UT_NAMESIZE,
+       if (strmode(sb->st_mode, &modep)) {
+               (void)fprintf(stderr, "find: %s.\n", strerror(errno));
+               exit(1);
+       }
+       (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE,
            user_from_uid(sb->st_uid, 0), UT_NAMESIZE,
            group_from_gid(sb->st_gid, 0));
 
            user_from_uid(sb->st_uid, 0), UT_NAMESIZE,
            group_from_gid(sb->st_gid, 0));
 
@@ -78,113 +83,6 @@ printtime(ftime)
        (void)putchar(' ');
 }
 
        (void)putchar(' ');
 }
 
-/*
- * do the permissions printing, passed the mode
- */
-printperms(mode)
-       mode_t mode;
-{
-       /* print type */
-       switch (mode & S_IFMT) {
-       case S_IFDIR:                   /* directory */
-               (void)putchar('d');
-               break;
-       case S_IFCHR:                   /* character special */
-               (void)putchar('c');
-               break;
-       case S_IFBLK:                   /* block special */
-               (void)putchar('b');
-               break;
-       case S_IFREG:                   /* regular */
-               (void)putchar('-');
-               break;
-       case S_IFLNK:                   /* symbolic link */
-               (void)putchar('l');
-               break;
-       case S_IFSOCK:                  /* socket */
-               (void)putchar('s');
-               break;
-#ifdef S_IFIFO
-       case S_IFIFO:                   /* fifo */
-               (void)putchar('p');
-               break;
-#endif
-       default:                        /* unknown */
-               (void)putchar('?');
-               break;
-       }
-       /* usr */
-       if (mode & S_IRUSR)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWUSR)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXUSR | S_ISUID)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXUSR:
-               (void)putchar('x');
-               break;
-       case S_ISUID:
-               (void)putchar('S');
-               break;
-       case S_IXUSR | S_ISUID:
-               (void)putchar('s');
-               break;
-       }
-       /* group */
-       if (mode & S_IRGRP)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWGRP)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXGRP | S_ISGID)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXGRP:
-               (void)putchar('x');
-               break;
-       case S_ISGID:
-               (void)putchar('S');
-               break;
-       case S_IXGRP | S_ISGID:
-               (void)putchar('s');
-               break;
-       }
-       /* other */
-       if (mode & S_IROTH)
-               (void)putchar('r');
-       else
-               (void)putchar('-');
-       if (mode & S_IWOTH)
-               (void)putchar('w');
-       else
-               (void)putchar('-');
-       switch (mode & (S_IXOTH | S_ISVTX)) {
-       case 0:
-               (void)putchar('-');
-               break;
-       case S_IXOTH:
-               (void)putchar('x');
-               break;
-       case S_ISVTX:
-               (void)putchar('T');
-               break;
-       case S_IXOTH | S_ISVTX:
-               (void)putchar('t');
-               break;
-       }
-       (void)putchar(' ');
-}
-
 printlink(name)
        char *name;
 {
 printlink(name)
        char *name;
 {