aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-02-21 09:56:37 -0800
committerPaul Eggert2011-02-21 09:56:37 -0800
commit5c185672d66dc89bfd2c7889a5f0a6984c0ec607 (patch)
tree0c3f95cac8c6d7258525c1e47db22f49e9d311f1 /src
parent06b840e0d96538cfa879eb524c9b030988f8e7c5 (diff)
parent2763cfc26857991fc4ccde9ff837c06032ac1008 (diff)
downloademacs-5c185672d66dc89bfd2c7889a5f0a6984c0ec607.tar.gz
emacs-5c185672d66dc89bfd2c7889a5f0a6984c0ec607.zip
Import filemode module from gnulib.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/Makefile.in2
-rw-r--r--src/config.in13
-rw-r--r--src/deps.mk3
-rw-r--r--src/dired.c5
-rw-r--r--src/filemode.c245
6 files changed, 27 insertions, 251 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c53e5add3fb..d95ebb32dee 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
12011-02-21 Paul Eggert <eggert@cs.ucla.edu>
2
3 Import filemode module from gnulib.
4 * Makefile.in (base_obj): Remove filemode.o, as it's now in ../lib.
5 * deps.mk (dired.o): Depend on ../lib/filemode.h, too.
6 (filemode.o): Remove; this is now in ../lib.
7 * dired.c: Include <filemode.h>.
8 (filemodestring): Remove now-redundant decl.
9 * config.in: Regenerate.
10
12011-02-20 Eli Zaretskii <eliz@gnu.org> 112011-02-20 Eli Zaretskii <eliz@gnu.org>
2 12
3 * makefile.w32-in ($(BLD)/fns.$(O)): Depend on 13 * makefile.w32-in ($(BLD)/fns.$(O)): Depend on
diff --git a/src/Makefile.in b/src/Makefile.in
index 41b6767f26e..e1195968f7f 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -347,7 +347,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
347 cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ) $(DBUS_OBJ) \ 347 cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ) $(DBUS_OBJ) \
348 emacs.o keyboard.o macros.o keymap.o sysdep.o \ 348 emacs.o keyboard.o macros.o keymap.o sysdep.o \
349 buffer.o filelock.o insdel.o marker.o \ 349 buffer.o filelock.o insdel.o marker.o \
350 minibuf.o fileio.o dired.o filemode.o \ 350 minibuf.o fileio.o dired.o \
351 cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \ 351 cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \
352 alloc.o data.o doc.o editfns.o callint.o \ 352 alloc.o data.o doc.o editfns.o callint.o \
353 eval.o floatfns.o fns.o font.o print.o lread.o \ 353 eval.o floatfns.o fns.o font.o print.o lread.o \
diff --git a/src/config.in b/src/config.in
index 9e8364ec45b..9c23fb583fa 100644
--- a/src/config.in
+++ b/src/config.in
@@ -152,6 +152,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
152 don't. */ 152 don't. */
153#undef HAVE_DECL_LOCALTIME_R 153#undef HAVE_DECL_LOCALTIME_R
154 154
155/* Define to 1 if you have the declaration of `strmode', and to 0 if you
156 don't. */
157#undef HAVE_DECL_STRMODE
158
155/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you 159/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
156 don't. */ 160 don't. */
157#undef HAVE_DECL_SYS_SIGLIST 161#undef HAVE_DECL_SYS_SIGLIST
@@ -686,6 +690,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
686/* Define to 1 if `struct utimbuf' is declared by <utime.h>. */ 690/* Define to 1 if `struct utimbuf' is declared by <utime.h>. */
687#undef HAVE_STRUCT_UTIMBUF 691#undef HAVE_STRUCT_UTIMBUF
688 692
693/* Define if struct stat has an st_dm_mode member. */
694#undef HAVE_ST_DM_MODE
695
689/* Define to 1 if you have the `sync' function. */ 696/* Define to 1 if you have the `sync' function. */
690#undef HAVE_SYNC 697#undef HAVE_SYNC
691 698
@@ -981,6 +988,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
981 STACK_DIRECTION = 0 => direction of growth unknown */ 988 STACK_DIRECTION = 0 => direction of growth unknown */
982#undef STACK_DIRECTION 989#undef STACK_DIRECTION
983 990
991/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
992#undef STAT_MACROS_BROKEN
993
984/* Define to 1 if you have the ANSI C header files. */ 994/* Define to 1 if you have the ANSI C header files. */
985#undef STDC_HEADERS 995#undef STDC_HEADERS
986 996
@@ -1149,6 +1159,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
1149/* Define to the name of the strftime replacement function. */ 1159/* Define to the name of the strftime replacement function. */
1150#undef my_strftime 1160#undef my_strftime
1151 1161
1162/* Define to the type of st_nlink in struct stat, or a supertype. */
1163#undef nlink_t
1164
1152/* Define to `int' if <sys/types.h> does not define. */ 1165/* Define to `int' if <sys/types.h> does not define. */
1153#undef pid_t 1166#undef pid_t
1154 1167
diff --git a/src/deps.mk b/src/deps.mk
index 5bd4a682bfa..77994bcaadb 100644
--- a/src/deps.mk
+++ b/src/deps.mk
@@ -73,7 +73,7 @@ pre-crt0.o: pre-crt0.c
73dbusbind.o: dbusbind.c termhooks.h frame.h keyboard.h lisp.h $(config_h) 73dbusbind.o: dbusbind.c termhooks.h frame.h keyboard.h lisp.h $(config_h)
74dired.o: dired.c commands.h buffer.h lisp.h $(config_h) character.h charset.h \ 74dired.o: dired.c commands.h buffer.h lisp.h $(config_h) character.h charset.h \
75 coding.h regex.h systime.h blockinput.h atimer.h composite.h \ 75 coding.h regex.h systime.h blockinput.h atimer.h composite.h \
76 ../lib/unistd.h globals.h 76 ../lib/filemode.h ../lib/unistd.h globals.h
77dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \ 77dispnew.o: dispnew.c systime.h commands.h process.h frame.h coding.h \
78 window.h buffer.h termchar.h termopts.h termhooks.h cm.h \ 78 window.h buffer.h termchar.h termopts.h termhooks.h cm.h \
79 disptab.h indent.h $(INTERVALS_H) nsgui.h ../lib/unistd.h \ 79 disptab.h indent.h $(INTERVALS_H) nsgui.h ../lib/unistd.h \
@@ -98,7 +98,6 @@ fileio.o: fileio.c window.h buffer.h systime.h $(INTERVALS_H) character.h \
98 commands.h globals.h ../lib/unistd.h 98 commands.h globals.h ../lib/unistd.h
99filelock.o: filelock.c buffer.h character.h coding.h systime.h composite.h \ 99filelock.o: filelock.c buffer.h character.h coding.h systime.h composite.h \
100 ../lib/unistd.h lisp.h globals.h $(config_h) 100 ../lib/unistd.h lisp.h globals.h $(config_h)
101filemode.o: filemode.c $(config_h)
102font.o: font.c dispextern.h frame.h window.h ccl.h character.h charset.h \ 101font.o: font.c dispextern.h frame.h window.h ccl.h character.h charset.h \
103 font.h lisp.h globals.h $(config_h) buffer.h composite.h fontset.h \ 102 font.h lisp.h globals.h $(config_h) buffer.h composite.h fontset.h \
104 xterm.h nsgui.h msdos.h 103 xterm.h nsgui.h msdos.h
diff --git a/src/dired.c b/src/dired.c
index 7b4b83cbe54..b01ce8d4d8f 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -61,6 +61,8 @@ extern struct direct *readdir (DIR *);
61 61
62#endif /* HAVE_DIRENT_H */ 62#endif /* HAVE_DIRENT_H */
63 63
64#include <filemode.h>
65
64#ifdef MSDOS 66#ifdef MSDOS
65#define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0) 67#define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0)
66#else 68#else
@@ -82,9 +84,6 @@ extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
82 struct re_registers *, 84 struct re_registers *,
83 Lisp_Object, int, int); 85 Lisp_Object, int, int);
84 86
85/* From filemode.c. Can't go in Lisp.h because of `stat'. */
86extern void filemodestring (struct stat *, char *);
87
88/* if system does not have symbolic links, it does not have lstat. 87/* if system does not have symbolic links, it does not have lstat.
89 In that case, use ordinary stat instead. */ 88 In that case, use ordinary stat instead. */
90 89
diff --git a/src/filemode.c b/src/filemode.c
deleted file mode 100644
index d41cd56c569..00000000000
--- a/src/filemode.c
+++ /dev/null
@@ -1,245 +0,0 @@
1/* filemode.c -- make a string describing file modes
2 Copyright (C) 1985, 1990, 1993, 2001-2011 Free Software Foundation, Inc.
3
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 3, or (at your option)
7 any later version.
8
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.
13
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA. */
18
19#include <config.h>
20#include <sys/types.h>
21#include <sys/stat.h>
22
23#if !S_IRUSR
24# if S_IREAD
25# define S_IRUSR S_IREAD
26# else
27# define S_IRUSR 00400
28# endif
29#endif
30
31#if !S_IWUSR
32# if S_IWRITE
33# define S_IWUSR S_IWRITE
34# else
35# define S_IWUSR 00200
36# endif
37#endif
38
39#if !S_IXUSR
40# if S_IEXEC
41# define S_IXUSR S_IEXEC
42# else
43# define S_IXUSR 00100
44# endif
45#endif
46
47#ifdef STAT_MACROS_BROKEN
48#undef S_ISBLK
49#undef S_ISCHR
50#undef S_ISDIR
51#undef S_ISFIFO
52#undef S_ISLNK
53#undef S_ISMPB
54#undef S_ISMPC
55#undef S_ISNWK
56#undef S_ISREG
57#undef S_ISSOCK
58#endif /* STAT_MACROS_BROKEN. */
59
60#if !defined(S_ISBLK) && defined(S_IFBLK)
61#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
62#endif
63#if !defined(S_ISCHR) && defined(S_IFCHR)
64#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
65#endif
66#if !defined(S_ISDIR) && defined(S_IFDIR)
67#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
68#endif
69#if !defined(S_ISREG) && defined(S_IFREG)
70#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
71#endif
72#if !defined(S_ISFIFO) && defined(S_IFIFO)
73#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
74#endif
75#if !defined(S_ISLNK) && defined(S_IFLNK)
76#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
77#endif
78#if !defined(S_ISSOCK) && defined(S_IFSOCK)
79#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
80#endif
81#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
82#define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
83#define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
84#endif
85#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
86#define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
87#endif
88
89void mode_string (short unsigned int mode, char *str);
90static char ftypelet (long int bits);
91static void rwx (short unsigned int bits, char *chars);
92static void setst (short unsigned int bits, char *chars);
93
94/* filemodestring - fill in string STR with an ls-style ASCII
95 representation of the st_mode field of file stats block STATP.
96 10 characters are stored in STR; no terminating null is added.
97 The characters stored in STR are:
98
99 0 File type. 'd' for directory, 'c' for character
100 special, 'b' for block special, 'm' for multiplex,
101 'l' for symbolic link, 's' for socket, 'p' for fifo,
102 '-' for regular, '?' for any other file type
103
104 1 'r' if the owner may read, '-' otherwise.
105
106 2 'w' if the owner may write, '-' otherwise.
107
108 3 'x' if the owner may execute, 's' if the file is
109 set-user-id, '-' otherwise.
110 'S' if the file is set-user-id, but the execute
111 bit isn't set.
112
113 4 'r' if group members may read, '-' otherwise.
114
115 5 'w' if group members may write, '-' otherwise.
116
117 6 'x' if group members may execute, 's' if the file is
118 set-group-id, '-' otherwise.
119 'S' if it is set-group-id but not executable.
120
121 7 'r' if any user may read, '-' otherwise.
122
123 8 'w' if any user may write, '-' otherwise.
124
125 9 'x' if any user may execute, 't' if the file is "sticky"
126 (will be retained in swap space after execution), '-'
127 otherwise.
128 'T' if the file is sticky but not executable. */
129
130void
131filemodestring (struct stat *statp, char *str)
132{
133 mode_string (statp->st_mode, str);
134}
135
136/* Like filemodestring, but only the relevant part of the `struct stat'
137 is given as an argument. */
138
139void
140mode_string (short unsigned int mode, char *str)
141{
142 str[0] = ftypelet ((long) mode);
143 rwx ((mode & 0700) << 0, &str[1]);
144 rwx ((mode & 0070) << 3, &str[4]);
145 rwx ((mode & 0007) << 6, &str[7]);
146 setst (mode, str);
147}
148
149/* Return a character indicating the type of file described by
150 file mode BITS:
151 'd' for directories
152 'b' for block special files
153 'c' for character special files
154 'm' for multiplexor files
155 'l' for symbolic links
156 's' for sockets
157 'p' for fifos
158 '-' for regular files
159 '?' for any other file type. */
160
161static char
162ftypelet (long int bits)
163{
164#ifdef S_ISBLK
165 if (S_ISBLK (bits))
166 return 'b';
167#endif
168 if (S_ISCHR (bits))
169 return 'c';
170 if (S_ISDIR (bits))
171 return 'd';
172 if (S_ISREG (bits))
173 return '-';
174#ifdef S_ISFIFO
175 if (S_ISFIFO (bits))
176 return 'p';
177#endif
178#ifdef S_ISLNK
179 if (S_ISLNK (bits))
180 return 'l';
181#endif
182#ifdef S_ISSOCK
183 if (S_ISSOCK (bits))
184 return 's';
185#endif
186#ifdef S_ISMPC
187 if (S_ISMPC (bits))
188 return 'm';
189#endif
190#ifdef S_ISNWK
191 if (S_ISNWK (bits))
192 return 'n';
193#endif
194 return '?';
195}
196
197/* Look at read, write, and execute bits in BITS and set
198 flags in CHARS accordingly. */
199
200static void
201rwx (short unsigned int bits, char *chars)
202{
203 chars[0] = (bits & S_IRUSR) ? 'r' : '-';
204 chars[1] = (bits & S_IWUSR) ? 'w' : '-';
205 chars[2] = (bits & S_IXUSR) ? 'x' : '-';
206}
207
208/* Set the 's' and 't' flags in file attributes string CHARS,
209 according to the file mode BITS. */
210
211static void
212setst (short unsigned int bits, char *chars)
213{
214#ifdef S_ISUID
215 if (bits & S_ISUID)
216 {
217 if (chars[3] != 'x')
218 /* Set-uid, but not executable by owner. */
219 chars[3] = 'S';
220 else
221 chars[3] = 's';
222 }
223#endif
224#ifdef S_ISGID
225 if (bits & S_ISGID)
226 {
227 if (chars[6] != 'x')
228 /* Set-gid, but not executable by group. */
229 chars[6] = 'S';
230 else
231 chars[6] = 's';
232 }
233#endif
234#ifdef S_ISVTX
235 if (bits & S_ISVTX)
236 {
237 if (chars[9] != 'x')
238 /* Sticky, but not executable by others. */
239 chars[9] = 'T';
240 else
241 chars[9] = 't';
242 }
243#endif
244}
245