1: #include "hd.h"
   2: #include "classify.h"
   3: #include "mydir.h"
   4: 
   5: #define aout1   0407
   6: #define aout2   0410
   7: #define aout3   0411
   8: #define aout4   0405
   9: #define cpio    070707
  10: #define ar  0177545
  11: 
  12: /* Classify return the file type of parameter fname */
  13: 
  14: classify (fname) char * fname; {
  15: 
  16:     int fdesc, rdlen, word;
  17:     unsigned mode;
  18: 
  19:     char *lastfn();
  20: 
  21:     if (stat (fname, &scr_stb)) return CL_NULL;
  22: 
  23:     mode = scr_stb.st_mode & S_IFMT;
  24:     if (mode == S_IFDIR) return CL_DIR;
  25:     if (mode != S_IFREG) return CL_SPCL;
  26: 
  27:     fdesc = open (fname, 0);
  28:     if (fdesc < 0) return CL_PROTPLN;
  29: 
  30:     rdlen = read (fdesc, &word, sizeof word);
  31:     close (fdesc);
  32:     if (rdlen < sizeof word) return CL_TEXT;
  33: 
  34:     if (word == aout1 || word == aout2 || word == aout3 ||
  35:         word == aout4) return CL_AOUT;
  36: 
  37:     if (word == ar) return CL_AR;
  38:     if (word == cpio) return CL_CPIO;
  39: 
  40:     if (compe (lastfn (fname), "core")) return CL_CORE;
  41: 
  42:     return CL_TEXT;
  43: }
  44: 
  45: /* Lastfn returns a pointer to the last file name in path.  */
  46: 
  47: char *
  48: lastfn (path) register char *path; {
  49:     register char *cp;
  50: 
  51:     for (cp=path; *cp++;);
  52: 
  53:     cp--;
  54:     while (*--cp != '/' && cp >= path);
  55: 
  56:     return ++cp;
  57: }

Defined functions

classify defined in line 14; used 3 times
lastfn defined in line 47; used 2 times

Defined macros

aout1 defined in line 5; used 1 times
  • in line 34
aout2 defined in line 6; used 1 times
  • in line 34
aout3 defined in line 7; used 1 times
  • in line 34
aout4 defined in line 8; used 1 times
  • in line 35
ar defined in line 10; used 1 times
  • in line 37
cpio defined in line 9; used 1 times
  • in line 38
Last modified: 1980-08-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 685
Valid CSS Valid XHTML 1.0 Strict