1 /* filemode.c -- make a string describing file modes
2 Copyright (C) 1985, 90, 91, 94, 95, 1997 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 static char ftypelet
PARAMS ((unsigned long));
23 static void setst
PARAMS ((unsigned long, char *));
25 /* filemodestring - fill in string STR with an ls-style ASCII
26 representation of the st_mode field of file stats block STATP.
27 10 characters are stored in STR; no terminating null is added.
28 The characters stored in STR are:
30 0 File type. 'd' for directory, 'c' for character
31 special, 'b' for block special, 'm' for multiplex,
32 'l' for symbolic link, 's' for socket, 'p' for fifo,
33 '-' for any other file type
35 1 'r' if the owner may read, '-' otherwise.
37 2 'w' if the owner may write, '-' otherwise.
39 3 'x' if the owner may execute, 's' if the file is
40 set-user-id, '-' otherwise.
41 'S' if the file is set-user-id, but the execute
44 4 'r' if group members may read, '-' otherwise.
46 5 'w' if group members may write, '-' otherwise.
48 6 'x' if group members may execute, 's' if the file is
49 set-group-id, '-' otherwise.
50 'S' if it is set-group-id but not executable.
52 7 'r' if any user may read, '-' otherwise.
54 8 'w' if any user may write, '-' otherwise.
56 9 'x' if any user may execute, 't' if the file is "sticky"
57 (will be retained in swap space after execution), '-'
59 'T' if the file is sticky but not executable. */
63 /* This is not used; only mode_string is used. */
66 filemodestring (statp
, str
)
70 mode_string ((unsigned long) statp
->st_mode
, str
);
75 /* Get definitions for the file permission bits. */
116 /* Like filemodestring, but only the relevant part of the `struct stat'
117 is given as an argument. */
120 mode_string (mode
, str
)
124 str
[0] = ftypelet ((unsigned long) mode
);
125 str
[1] = (mode
& S_IRUSR
) != 0 ? 'r' : '-';
126 str
[2] = (mode
& S_IWUSR
) != 0 ? 'w' : '-';
127 str
[3] = (mode
& S_IXUSR
) != 0 ? 'x' : '-';
128 str
[4] = (mode
& S_IRGRP
) != 0 ? 'r' : '-';
129 str
[5] = (mode
& S_IWGRP
) != 0 ? 'w' : '-';
130 str
[6] = (mode
& S_IXGRP
) != 0 ? 'x' : '-';
131 str
[7] = (mode
& S_IROTH
) != 0 ? 'r' : '-';
132 str
[8] = (mode
& S_IWOTH
) != 0 ? 'w' : '-';
133 str
[9] = (mode
& S_IXOTH
) != 0 ? 'x' : '-';
134 setst ((unsigned long) mode
, str
);
137 /* Return a character indicating the type of file described by
140 'b' for block special files
141 'c' for character special files
142 'm' for multiplexor files
143 'l' for symbolic links
146 '-' for any other file type. */
150 #define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR)
151 #else /* ! defined (S_IFDIR) */
152 #define S_ISDIR(i) (((i) & 0170000) == 040000)
153 #endif /* ! defined (S_IFDIR) */
154 #endif /* ! defined (S_ISDIR) */
158 #define S_ISBLK(i) (((i) & S_IFMT) == S_IFBLK)
159 #else /* ! defined (S_IFBLK) */
161 #endif /* ! defined (S_IFBLK) */
162 #endif /* ! defined (S_ISBLK) */
166 #define S_ISCHR(i) (((i) & S_IFMT) == S_IFCHR)
167 #else /* ! defined (S_IFCHR) */
169 #endif /* ! defined (S_IFCHR) */
170 #endif /* ! defined (S_ISCHR) */
174 #define S_ISFIFO(i) (((i) & S_IFMT) == S_IFIFO)
175 #else /* ! defined (S_IFIFO) */
176 #define S_ISFIFO(i) 0
177 #endif /* ! defined (S_IFIFO) */
178 #endif /* ! defined (S_ISFIFO) */
182 #define S_ISSOCK(i) (((i) & S_IFMT) == S_IFSOCK)
183 #else /* ! defined (S_IFSOCK) */
184 #define S_ISSOCK(i) 0
185 #endif /* ! defined (S_IFSOCK) */
186 #endif /* ! defined (S_ISSOCK) */
190 #define S_ISLNK(i) (((i) & S_IFMT) == S_IFLNK)
191 #else /* ! defined (S_IFLNK) */
193 #endif /* ! defined (S_IFLNK) */
194 #endif /* ! defined (S_ISLNK) */
215 if ((bits
& S_IFMT
) == S_IFMPC
216 || (bits
& S_IFMT
) == S_IFMPB
)
220 if ((bits
& S_IFMT
) == S_IFNWK
)
228 /* Set the 's' and 't' flags in file attributes string CHARS,
229 according to the file mode BITS. */
240 /* Set-uid, but not executable by owner. */
250 /* Set-gid, but not executable by group. */
260 /* Sticky, but not executable by others. */