Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/filemode.c @ 7292:17785d5bede0
Fix docstrings
author | Sergey Poznyakoff <gray@gnu.org.ua> |
---|---|
date | Sun, 10 Sep 2006 11:52:44 +0000 |
parents | 314715e0260d |
children | 8a1a9361108c |
rev | line source |
---|---|
5 | 1 /* filemode.c -- make a string describing file modes |
6912 | 2 |
3 Copyright (C) 1985, 1990, 1993, 1998-2000, 2004, 2006 Free Software | |
4 Foundation, Inc. | |
5 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
345
diff
changeset
|
17 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
2426
b22a7367bcf5
Use `C' to denote so-called `contiguous' files, the same way that tar does.
Jim Meyering <jim@meyering.net>
parents:
1814
diff
changeset
|
19 |
6259
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
1278
9ad625a30b7d
Use #if, not #ifdef with HAVE_ macros
Jim Meyering <jim@meyering.net>
parents:
711
diff
changeset
|
21 # include <config.h> |
297 | 22 #endif |
23 | |
6912 | 24 #include "filemode.h" |
297 | 25 |
5159 | 26 #include "stat-macros.h" |
2426
b22a7367bcf5
Use `C' to denote so-called `contiguous' files, the same way that tar does.
Jim Meyering <jim@meyering.net>
parents:
1814
diff
changeset
|
27 |
6912 | 28 /* The following is for Cray DMF (Data Migration Facility), which is a |
29 HSM file system. A migrated file has a `st_dm_mode' that is | |
30 different from the normal `st_mode', so any tests for migrated | |
31 files should use the former. */ | |
32 #if HAVE_ST_DM_MODE | |
33 # define IS_MIGRATED_FILE(statp) \ | |
34 (S_ISOFD (statp->st_dm_mode) || S_ISOFL (statp->st_dm_mode)) | |
35 #else | |
36 # define IS_MIGRATED_FILE(statp) 0 | |
37 #endif | |
5 | 38 |
6912 | 39 #if ! HAVE_DECL_STRMODE |
5 | 40 |
41 /* Return a character indicating the type of file described by | |
42 file mode BITS: | |
6912 | 43 '-' regular file |
44 'b' block special file | |
45 'c' character special file | |
46 'C' high performance ("contiguous data") file | |
47 'd' directory | |
48 'D' door | |
49 'l' symbolic link | |
50 'm' multiplexed file (7th edition Unix; obsolete) | |
51 'n' network special file (HP-UX) | |
52 'p' fifo (named pipe) | |
53 'P' port | |
54 's' socket | |
55 'w' whiteout (4.4BSD) | |
56 '?' some other file type */ | |
5 | 57 |
58 static char | |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
59 ftypelet (mode_t bits) |
5 | 60 { |
6912 | 61 /* These are the most common, so test for them first. */ |
62 if (S_ISREG (bits)) | |
63 return '-'; | |
64 if (S_ISDIR (bits)) | |
65 return 'd'; | |
66 | |
67 /* Other letters standardized by POSIX 1003.1-2004. */ | |
5 | 68 if (S_ISBLK (bits)) |
69 return 'b'; | |
70 if (S_ISCHR (bits)) | |
71 return 'c'; | |
6912 | 72 if (S_ISLNK (bits)) |
73 return 'l'; | |
5 | 74 if (S_ISFIFO (bits)) |
75 return 'p'; | |
6912 | 76 |
77 /* Other file types (though not letters) standardized by POSIX. */ | |
5 | 78 if (S_ISSOCK (bits)) |
79 return 's'; | |
6912 | 80 |
81 /* Nonstandard file types. */ | |
82 if (S_ISCTG (bits)) | |
83 return 'C'; | |
84 if (S_ISDOOR (bits)) | |
85 return 'D'; | |
86 if (S_ISMPB (bits) || S_ISMPC (bits)) | |
5 | 87 return 'm'; |
88 if (S_ISNWK (bits)) | |
89 return 'n'; | |
6912 | 90 if (S_ISPORT (bits)) |
91 return 'P'; | |
92 if (S_ISWHT (bits)) | |
93 return 'w'; | |
711
e80b482cadad
(ftypelet): Add support for Cray's migrated dmf files.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
94 |
5 | 95 return '?'; |
96 } | |
97 | |
6912 | 98 /* Like filemodestring, but rely only on MODE. */ |
5 | 99 |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
100 void |
6912 | 101 strmode (mode_t mode, char *str) |
5 | 102 { |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
103 str[0] = ftypelet (mode); |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
104 str[1] = mode & S_IRUSR ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
105 str[2] = mode & S_IWUSR ? 'w' : '-'; |
6912 | 106 str[3] = (mode & S_ISUID |
107 ? (mode & S_IXUSR ? 's' : 'S') | |
108 : (mode & S_IXUSR ? 'x' : '-')); | |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
109 str[4] = mode & S_IRGRP ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
110 str[5] = mode & S_IWGRP ? 'w' : '-'; |
6912 | 111 str[6] = (mode & S_ISGID |
112 ? (mode & S_IXGRP ? 's' : 'S') | |
113 : (mode & S_IXGRP ? 'x' : '-')); | |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
114 str[7] = mode & S_IROTH ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
115 str[8] = mode & S_IWOTH ? 'w' : '-'; |
6912 | 116 str[9] = (mode & S_ISVTX |
117 ? (mode & S_IXOTH ? 't' : 'T') | |
118 : (mode & S_IXOTH ? 'x' : '-')); | |
119 str[10] = ' '; | |
120 str[11] = '\0'; | |
5 | 121 } |
122 | |
6912 | 123 #endif /* ! HAVE_DECL_STRMODE */ |
124 | |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
125 /* filemodestring - fill in string STR with an ls-style ASCII |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
126 representation of the st_mode field of file stats block STATP. |
6912 | 127 12 characters are stored in STR. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
128 The characters stored in STR are: |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
129 |
6912 | 130 0 File type, as in ftypelet above, except that other letters are used |
131 for files whose type cannot be determined solely from st_mode: | |
132 | |
133 'F' semaphore | |
134 'M' migrated file (Cray DMF) | |
135 'Q' message queue | |
136 'S' shared memory object | |
137 'T' typed memory object | |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
138 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
139 1 'r' if the owner may read, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
140 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
141 2 'w' if the owner may write, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
142 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
143 3 'x' if the owner may execute, 's' if the file is |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
144 set-user-id, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
145 'S' if the file is set-user-id, but the execute |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
146 bit isn't set. |
5 | 147 |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
148 4 'r' if group members may read, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
149 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
150 5 'w' if group members may write, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
151 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
152 6 'x' if group members may execute, 's' if the file is |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
153 set-group-id, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
154 'S' if it is set-group-id but not executable. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
155 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
156 7 'r' if any user may read, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
157 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
158 8 'w' if any user may write, '-' otherwise. |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
159 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
160 9 'x' if any user may execute, 't' if the file is "sticky" |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
161 (will be retained in swap space after execution), '-' |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
162 otherwise. |
6912 | 163 'T' if the file is sticky but not executable. |
164 | |
165 10 ' ' for compatibility with 4.4BSD strmode, | |
166 since this interface does not support ACLs. | |
167 | |
168 11 '\0'. */ | |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
169 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
170 void |
6912 | 171 filemodestring (struct stat const *statp, char *str) |
5 | 172 { |
6912 | 173 strmode (statp->st_mode, str); |
174 | |
175 if (S_TYPEISSEM (statp)) | |
176 str[0] = 'F'; | |
177 else if (IS_MIGRATED_FILE (statp)) | |
178 str[0] = 'M'; | |
179 else if (S_TYPEISMQ (statp)) | |
180 str[0] = 'Q'; | |
181 else if (S_TYPEISSHM (statp)) | |
182 str[0] = 'S'; | |
183 else if (S_TYPEISTMO (statp)) | |
184 str[0] = 'T'; | |
5 | 185 } |