annotate src/filemode.c @ 42047:83eb799f3657

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