annotate src/filemode.c @ 104823:68150c643e2e

Use default-value rather than default-enable-multibyte-characters.
author Glenn Morris <rgm@gnu.org>
date Thu, 03 Sep 2009 06:54:57 +0000
parents e038c1a8307c
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
1 /* filemode.c -- make a string describing file modes
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
2 Copyright (C) 1985, 1990, 1993, 2001, 2002, 2003, 2004,
100951
e038c1a8307c Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
3 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
4
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
78260
922696f363b0 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75227
diff changeset
7 the Free Software Foundation; either version 3, or (at your option)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
8 any later version.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
9
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
13 GNU General Public License for more details.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
14
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
18 USA. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
19
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
21 #include <config.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
22 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
23
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
24 #include <sys/types.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
25 #include <sys/stat.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
26
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
27 #if !S_IRUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
28 # if S_IREAD
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
29 # define S_IRUSR S_IREAD
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
30 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
31 # define S_IRUSR 00400
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
32 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
33 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
34
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
35 #if !S_IWUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
36 # if S_IWRITE
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
37 # define S_IWUSR S_IWRITE
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
38 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
39 # define S_IWUSR 00200
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
40 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
41 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
42
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
43 #if !S_IXUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
44 # if S_IEXEC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
45 # define S_IXUSR S_IEXEC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
46 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
47 # define S_IXUSR 00100
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
48 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
49 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
50
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
51 #ifdef STAT_MACROS_BROKEN
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
52 #undef S_ISBLK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
53 #undef S_ISCHR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
54 #undef S_ISDIR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
55 #undef S_ISFIFO
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
56 #undef S_ISLNK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
57 #undef S_ISMPB
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
58 #undef S_ISMPC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
59 #undef S_ISNWK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
60 #undef S_ISREG
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
61 #undef S_ISSOCK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
62 #endif /* STAT_MACROS_BROKEN. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
63
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
64 #if !defined(S_ISBLK) && defined(S_IFBLK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
65 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
66 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
67 #if !defined(S_ISCHR) && defined(S_IFCHR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
68 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
69 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
70 #if !defined(S_ISDIR) && defined(S_IFDIR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
71 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
72 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
73 #if !defined(S_ISREG) && defined(S_IFREG)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
74 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
75 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
76 #if !defined(S_ISFIFO) && defined(S_IFIFO)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
77 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
78 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
79 #if !defined(S_ISLNK) && defined(S_IFLNK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
80 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
81 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
82 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
83 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
84 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
85 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
86 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
87 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
88 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
89 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
90 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
91 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
92
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
93 void mode_string ();
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
94 static char ftypelet ();
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
95 static void rwx ();
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
96 static void setst ();
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
97
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
98 /* filemodestring - fill in string STR with an ls-style ASCII
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
99 representation of the st_mode field of file stats block STATP.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
100 10 characters are stored in STR; no terminating null is added.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
101 The characters stored in STR are:
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
102
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
103 0 File type. 'd' for directory, 'c' for character
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
104 special, 'b' for block special, 'm' for multiplex,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
105 'l' for symbolic link, 's' for socket, 'p' for fifo,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
106 '-' for regular, '?' for any other file type
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
107
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
108 1 'r' if the owner may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
109
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
110 2 'w' if the owner may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
111
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
112 3 'x' if the owner may execute, 's' if the file is
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
113 set-user-id, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
114 'S' if the file is set-user-id, but the execute
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
115 bit isn't set.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
116
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
117 4 'r' if group members may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
118
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
119 5 'w' if group members may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
120
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
121 6 'x' if group members may execute, 's' if the file is
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
122 set-group-id, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
123 'S' if it is set-group-id but not executable.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
124
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
125 7 'r' if any user may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
126
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
127 8 'w' if any user may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
128
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
129 9 'x' if any user may execute, 't' if the file is "sticky"
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (will be retained in swap space after execution), '-'
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
131 otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
132 'T' if the file is sticky but not executable. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
133
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
134 void
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
135 filemodestring (statp, str)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
136 struct stat *statp;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
137 char *str;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
138 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
139 mode_string (statp->st_mode, str);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
140 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
141
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
142 /* Like filemodestring, but only the relevant part of the `struct stat'
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
143 is given as an argument. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
144
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
145 void
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
146 mode_string (mode, str)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
147 unsigned short mode;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
148 char *str;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
149 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
150 str[0] = ftypelet ((long) mode);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
151 rwx ((mode & 0700) << 0, &str[1]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
152 rwx ((mode & 0070) << 3, &str[4]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
153 rwx ((mode & 0007) << 6, &str[7]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
154 setst (mode, str);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
155 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
156
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
157 /* Return a character indicating the type of file described by
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
158 file mode BITS:
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
159 'd' for directories
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
160 'b' for block special files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
161 'c' for character special files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
162 'm' for multiplexor files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
163 'l' for symbolic links
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
164 's' for sockets
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
165 'p' for fifos
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
166 '-' for regular files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
167 '?' for any other file type. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
168
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
169 static char
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
170 ftypelet (bits)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
171 long bits;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
172 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
173 #ifdef S_ISBLK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
174 if (S_ISBLK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
175 return 'b';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
176 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
177 if (S_ISCHR (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
178 return 'c';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
179 if (S_ISDIR (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
180 return 'd';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
181 if (S_ISREG (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
182 return '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
183 #ifdef S_ISFIFO
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
184 if (S_ISFIFO (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
185 return 'p';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
186 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
187 #ifdef S_ISLNK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
188 if (S_ISLNK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
189 return 'l';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
190 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
191 #ifdef S_ISSOCK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
192 if (S_ISSOCK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
193 return 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
194 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
195 #ifdef S_ISMPC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
196 if (S_ISMPC (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
197 return 'm';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
198 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
199 #ifdef S_ISNWK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
200 if (S_ISNWK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
201 return 'n';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
202 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
203 return '?';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
204 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
205
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
206 /* Look at read, write, and execute bits in BITS and set
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
207 flags in CHARS accordingly. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
208
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
209 static void
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
210 rwx (bits, chars)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
211 unsigned short bits;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
212 char *chars;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
213 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
214 chars[0] = (bits & S_IRUSR) ? 'r' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
215 chars[1] = (bits & S_IWUSR) ? 'w' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
216 chars[2] = (bits & S_IXUSR) ? 'x' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
217 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
218
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
219 /* Set the 's' and 't' flags in file attributes string CHARS,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
220 according to the file mode BITS. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
221
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
222 static void
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
223 setst (bits, chars)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
224 unsigned short bits;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
225 char *chars;
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
226 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
227 #ifdef S_ISUID
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
228 if (bits & S_ISUID)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
229 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
230 if (chars[3] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
231 /* Set-uid, but not executable by owner. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
232 chars[3] = 'S';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
233 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
234 chars[3] = 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
235 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
236 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
237 #ifdef S_ISGID
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
238 if (bits & S_ISGID)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
239 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
240 if (chars[6] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
241 /* Set-gid, but not executable by group. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
242 chars[6] = 'S';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
243 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
244 chars[6] = 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
245 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
246 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
247 #ifdef S_ISVTX
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
248 if (bits & S_ISVTX)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
249 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
250 if (chars[9] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
251 /* Sticky, but not executable by others. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
252 chars[9] = 'T';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
253 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
254 chars[9] = 't';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
255 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
256 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
257 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
258
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
259 /* arch-tag: 4340830c-15a5-47d2-b45f-1d43c45a91bb
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
260 (do not change this comment) */