1 /* filemode.c -- make a string describing file modes
2 Copyright (C) 1985, 1990 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 of the License, or
7 (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <sys/types.h>
22 static char ftypelet ();
26 /* filemodestring - fill in string STR with an ls-style ASCII
27 representation of the st_mode field of file stats block STATP.
28 10 characters are stored in STR; no terminating null is added.
29 The characters stored in STR are:
31 0 File type. 'd' for directory, 'c' for character
32 special, 'b' for block special, 'm' for multiplex,
33 'l' for symbolic link, 's' for socket, 'p' for fifo,
34 '-' for any other file type
36 1 'r' if the owner may read, '-' otherwise.
38 2 'w' if the owner may write, '-' otherwise.
40 3 'x' if the owner may execute, 's' if the file is
41 set-user-id, '-' otherwise.
42 'S' if the file is set-user-id, but the execute
45 4 'r' if group members may read, '-' otherwise.
47 5 'w' if group members may write, '-' otherwise.
49 6 'x' if group members may execute, 's' if the file is
50 set-group-id, '-' otherwise.
51 'S' if it is set-group-id but not executable.
53 7 'r' if any user may read, '-' otherwise.
55 8 'w' if any user may write, '-' otherwise.
57 9 'x' if any user may execute, 't' if the file is "sticky"
58 (will be retained in swap space after execution), '-'
60 'T' if the file is sticky but not executable. */
63 filemodestring (statp
, str
)
67 mode_string (statp
->st_mode
, str
);
70 /* Like filemodestring, but only the relevant part of the `struct stat'
71 is given as an argument. */
74 mode_string (mode
, str
)
78 str
[0] = ftypelet (mode
);
79 rwx ((mode
& 0700) << 0, &str
[1]);
80 rwx ((mode
& 0070) << 3, &str
[4]);
81 rwx ((mode
& 0007) << 6, &str
[7]);
85 /* Return a character indicating the type of file described by
88 'b' for block special files
89 'c' for character special files
90 'm' for multiplexor files
91 'l' for symbolic links
94 '-' for any other file type. */
100 switch (bits
& S_IFMT
)
128 #if S_IFIFO != S_IFSOCK
133 #ifdef S_IFNWK /* HP-UX */
140 /* Look at read, write, and execute bits in BITS and set
141 flags in CHARS accordingly. */
148 chars
[0] = (bits
& S_IREAD
) ? 'r' : '-';
149 chars
[1] = (bits
& S_IWRITE
) ? 'w' : '-';
150 chars
[2] = (bits
& S_IEXEC
) ? 'x' : '-';
153 /* Set the 's' and 't' flags in file attributes string CHARS,
154 according to the file mode BITS. */
165 /* Set-uid, but not executable by owner. */
175 /* Set-gid, but not executable by group. */
185 /* Sticky, but not executable by others. */
This page took 0.033134 seconds and 4 git commands to generate.