BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / file / file.c
index d0fa502..a14c39b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)file.c     4.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)file.c     4.17 (Berkeley) 7/1/90";
 #endif
 /*
  * file - determine type of file
 #endif
 /*
  * file - determine type of file
@@ -7,12 +7,13 @@ static        char sccsid[] = "@(#)file.c     4.12 (Berkeley) %G%";
 
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <a.out.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <a.out.h>
-int    errno;
-int    sys_nerr;
-char   *sys_errlist[];
+
+extern int     errno;
+
 int in;
 int i  = 0;
 char buf[BUFSIZ];
 int in;
 int i  = 0;
 char buf[BUFSIZ];
@@ -41,7 +42,6 @@ char **argv;
        FILE *fl;
        register char *p;
        char ap[MAXPATHLEN + 1];
        FILE *fl;
        register char *p;
        char ap[MAXPATHLEN + 1];
-       extern char _sobuf[];
 
        if (argc < 2) {
                fprintf(stderr, "usage: %s file ...\n", argv[0]);
 
        if (argc < 2) {
                fprintf(stderr, "usage: %s file ...\n", argv[0]);
@@ -57,7 +57,6 @@ char **argv;
                        int l = strlen(p);
                        if (l>0)
                                p[l-1] = '\0';
                        int l = strlen(p);
                        if (l>0)
                                p[l-1] = '\0';
-                       printf("%s:     ", p);
                        type(p);
                        if (ifile>=0)
                                close(ifile);
                        type(p);
                        if (ifile>=0)
                                close(ifile);
@@ -65,7 +64,6 @@ char **argv;
                exit(1);
        }
        while(argc > 1) {
                exit(1);
        }
        while(argc > 1) {
-               printf("%s:     ", argv[1]);
                type(argv[1]);
                fflush(stdout);
                argc--;
                type(argv[1]);
                fflush(stdout);
                argc--;
@@ -86,10 +84,10 @@ char *file;
 
        ifile = -1;
        if (lstat(file, &mbuf) < 0) {
 
        ifile = -1;
        if (lstat(file, &mbuf) < 0) {
-               printf("%s\n",
-               (unsigned)errno < sys_nerr? sys_errlist[errno]: "Cannot stat");
+               fprintf(stderr, "file: %s: %s\n", file, strerror(errno));
                return;
        }
                return;
        }
+       printf("%s:\t", file);
        switch (mbuf.st_mode & S_IFMT) {
 
        case S_IFLNK:
        switch (mbuf.st_mode & S_IFMT) {
 
        case S_IFLNK:
@@ -122,8 +120,7 @@ char *file;
 
        ifile = open(file, 0);
        if(ifile < 0) {
 
        ifile = open(file, 0);
        if(ifile < 0) {
-               printf("%s\n",
-               (unsigned)errno < sys_nerr? sys_errlist[errno]: "Cannot read");
+               fprintf(stderr, "file: %s: %s\n", file, strerror(errno));
                return;
        }
        in = read(ifile, buf, BUFSIZ);
                return;
        }
        in = read(ifile, buf, BUFSIZ);
@@ -420,7 +417,7 @@ char *bp;
                ct[j]=0;
        for(j=0; j<n; j++)
        {
                ct[j]=0;
        for(j=0; j<n; j++)
        {
-               if (bp[j]<NASC)
+               if ((u_char)bp[j]<NASC)
                        ct[bp[j]|040]++;
                switch (bp[j])
                {
                        ct[bp[j]|040]++;
                switch (bp[j])
                {