1: /* Examine the result of  stat  and make a string describing file modes.
   2:    Copyright (C) 1985 Richard M. Stallman.
   3: 
   4: This file is part of GNU Emacs.
   5: 
   6: GNU Emacs is distributed in the hope that it will be useful,
   7: but WITHOUT ANY WARRANTY.  No author or distributor
   8: accepts responsibility to anyone for the consequences of using it
   9: or for whether it serves any particular purpose or works at all,
  10: unless he says so in writing.  Refer to the GNU Emacs General Public
  11: License for full details.
  12: 
  13: Everyone is granted permission to copy, modify and redistribute
  14: GNU Emacs, but only under the conditions described in the
  15: GNU Emacs General Public License.   A copy of this license is
  16: supposed to have been given to you along with GNU Emacs so you
  17: can know your rights and responsibilities.  It should be in a
  18: file named COPYING.  Among other things, the copyright notice
  19: and this notice must be preserved on all copies.  */
  20: 
  21: 
  22: #include <sys/types.h>
  23: #include <sys/stat.h>
  24: 
  25: /* filemodestring - set file attribute data
  26: 
  27: *** WARNING!  FILE STRUCTURE DEPENDENT ***
  28: 
  29:    Filemodestring converts the data in the st_mode field of file status
  30: block `s' to a 10 character attribute string, which it stores in
  31: the block that `a' points to.
  32: This attribute string is modelled after the string produced by the Berkeley ls.
  33: 
  34: As usual under Unix, the elements of the string are numbered
  35: from 0.  Their meanings are:
  36: 
  37:    0	File type.  'd' for directory, 'c' for character
  38: 	special, 'b' for block special, 'm' for multiplex, '-'
  39: 	for any other file type
  40: 
  41:    1	'r' if the owner may read, '-' otherwise.
  42: 
  43:    2	'w' if the owner may write, '-' otherwise.
  44: 
  45:    3	'x' if the owner may execute, 's' if the file is
  46: 	set-user-id, '-' otherwise.
  47: 
  48:    4	'r' if group members may read, '-' otherwise.
  49: 
  50:    5	'w' if group members may write, '-' otherwise.
  51: 
  52:    6	'x' if group members may execute, 's' if the file is
  53: 	set-group-id, '-' otherwise.
  54: 
  55:    7	'r' if any user may read, '-' otherwise.
  56: 
  57:    8	'w' if any user may write, '-' otherwise.
  58: 
  59:    9	'x' if any user may execute, 't' if the file is "sticky"
  60: 	(will be retained in swap space after execution), '-'
  61: 	otherwise.
  62: 
  63:  */
  64: 
  65: #define TEXT char
  66: #define VOID void
  67: 
  68: static TEXT ftypelet ();
  69: static VOID rwx (), setst ();
  70: 
  71: VOID
  72: filemodestring (s,a)
  73:    struct stat  *s;
  74:    TEXT *a;
  75: {
  76:    a[0] = ftypelet(s);
  77:    rwx ((s->st_mode&0700)<<0, &(a[1]));
  78:    rwx ((s->st_mode&0070)<<3, &(a[4]));
  79:    rwx ((s->st_mode&0007)<<6, &(a[7]));
  80:    setst (s->st_mode, a);
  81: }
  82: 
  83: /* ftypelet - file type letter
  84: 
  85: *** WARNING!  FILE STRUCTURE DEPENDENT ***
  86: 
  87:    Ftypelet accepts a file status block and returns a character
  88: code describing the type of the file.  'd' is returned for
  89: directories, 'b' for block special files, 'c' for character
  90: special files, 'm' for multiplexor files, and '-' for regular
  91: files.
  92: 
  93:  */
  94: 
  95: static TEXT
  96: ftypelet(s)
  97:    struct stat *s;
  98: {
  99: 
 100:    if ((s->st_mode&S_IFMT)==S_IFDIR)
 101:       return 'd';
 102:    else if ((s->st_mode&S_IFMT)==S_IFCHR)
 103:       return 'c';
 104:    else if ((s->st_mode&S_IFMT)==S_IFBLK)
 105:       return 'b';
 106: /* These do not seem to exist */
 107: /*   else if ((s->st_mode&S_IFMT)==S_IFMPC ||
 108: 	    (s->st_mode&S_IFMT)==S_IFMPB)
 109:       return 'm';
 110:  */
 111:    else
 112:       return '-';
 113: }
 114: 
 115: 
 116: /* rwx - look at read, write, and execute bits and set character
 117: flags accordingly
 118: 
 119: *** WARNING!  FILE STRUCTURE DEPENDENT ***
 120: 
 121:  */
 122: 
 123: static VOID
 124: rwx (bits, chars)
 125:    unsigned short bits;
 126:    TEXT chars[];
 127: {
 128:     chars[0] = chars[1] = chars[2] = '-';
 129:    if (bits&S_IREAD)
 130:       chars[0] = 'r';
 131:    if (bits&S_IWRITE)
 132:       chars[1] = 'w';
 133:    if (bits&S_IEXEC)
 134:       chars[2] = 'x';
 135: }
 136: 
 137: 
 138: /* setst - set s & t flags in a file attributes string */
 139: /* *** WARNING!  FILE STRUCTURE DEPENDENT *** */
 140: static VOID
 141: setst (bits, chars)
 142:    unsigned short bits;
 143:    TEXT chars[];
 144: {
 145:    if (bits&S_ISUID)
 146:       chars[3] = 's';
 147:    if (bits&S_ISGID)
 148:       chars[6] = 's';
 149:    if (bits&S_ISVTX)
 150:       chars[9] = 't';
 151: }

Defined functions

filemodestring defined in line 71; used 1 times
ftypelet defined in line 95; used 2 times
rwx defined in line 123; used 4 times
setst defined in line 140; used 2 times

Defined macros

TEXT defined in line 65; used 5 times
VOID defined in line 66; used 4 times
Last modified: 1985-11-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 555
Valid CSS Valid XHTML 1.0 Strict