0
|
1 /*
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not really in FSF. */
|
|
22
|
|
23 #include <errno.h>
|
100
|
24
|
|
25 #ifndef WINDOWSNT
|
0
|
26 #include <sys/errno.h> /* <errno.h> does not always imply this */
|
100
|
27 #endif
|
|
28
|
0
|
29 /* Load sys/types.h if not already loaded.
|
|
30 In some systems loading it twice is suicidal. */
|
|
31 #ifndef makedev
|
|
32 #include <sys/types.h> /* some typedefs are used in sys/file.h */
|
|
33 #endif
|
|
34 #include <sys/file.h>
|
|
35 #include <sys/stat.h>
|
|
36 #include <sys/param.h>
|
|
37
|
251
|
38 #if defined (NeXT) || defined(__CYGWIN32__)
|
|
39 /* what is needed from here? Do others need it too?
|
|
40 O_BINARY is in here under cygwin. */
|
0
|
41 # include <sys/fcntl.h>
|
|
42 #endif /* NeXT */
|
|
43
|
|
44 #ifdef WINDOWSNT
|
100
|
45 #include <io.h>
|
|
46 #endif
|
|
47
|
|
48 #if 0
|
|
49 #ifdef WINDOWSNT
|
0
|
50 #include <windows.h>
|
|
51 #include <stdlib.h> /* for proper declaration of environ */
|
|
52 #include <fcntl.h>
|
|
53 #include "nt.h"
|
|
54 #define _P_NOWAIT 1 /* from process.h */
|
|
55 #endif
|
100
|
56 #endif
|
0
|
57
|
|
58 #ifdef MSDOS
|
|
59 #include <dos.h>
|
|
60 #include "msdos.h"
|
|
61 #endif /* MSDOS */
|
|
62
|
|
63 #ifndef O_RDONLY
|
|
64 #define O_RDONLY 0
|
|
65 #endif
|
|
66
|
|
67 #ifndef O_WRONLY
|
|
68 #define O_WRONLY 1
|
|
69 #endif
|
|
70
|
|
71 #ifndef O_RDWR
|
|
72 #define O_RDWR 2
|
|
73 #endif
|
|
74
|
251
|
75 /* file opening defaults */
|
|
76 #ifndef OPEN_BINARY
|
|
77 #ifdef O_BINARY
|
|
78 #define OPEN_BINARY O_BINARY
|
|
79 #else
|
|
80 #define OPEN_BINARY (0)
|
|
81 #endif
|
|
82 #endif
|
|
83
|
|
84 #ifndef OPEN_TEXT
|
|
85 #ifdef O_TEXT
|
|
86 #define OPEN_TEXT O_TEXT
|
|
87 #else
|
|
88 #define OPEN_TEXT (0)
|
|
89 #endif
|
|
90 #endif
|
|
91
|
|
92 #ifndef CREAT_MODE
|
|
93 #ifdef WINDOWSNT
|
|
94 #define CREAT_MODE (S_IREAD | S_IWRITE)
|
|
95 #else
|
|
96 #define CREAT_MODE (0666)
|
|
97 #endif
|
|
98 #endif
|
|
99
|
|
100 #ifndef READ_TEXT
|
|
101 #ifdef O_TEXT
|
|
102 #define READ_TEXT "rt"
|
|
103 #else
|
|
104 #define READ_TEXT "r"
|
|
105 #endif
|
|
106 #endif
|
|
107
|
|
108 #ifndef READ_BINARY
|
|
109 #ifdef O_BINARY
|
|
110 #define READ_BINARY "rb"
|
|
111 #else
|
|
112 #define READ_BINARY "r"
|
|
113 #endif
|
|
114 #endif
|
|
115
|
|
116 #ifndef WRITE_BINARY
|
|
117 #ifdef O_BINARY
|
|
118 #define WRITE_BINARY "wb"
|
|
119 #else
|
|
120 #define WRITE_BINARY "w"
|
|
121 #endif
|
|
122 #endif
|
|
123
|
0
|
124 /* if system does not have symbolic links, it does not have lstat.
|
|
125 In that case, use ordinary stat instead. */
|
|
126
|
|
127 #ifndef S_IFLNK
|
|
128 #define lstat stat
|
|
129 #endif
|
|
130
|
|
131 #if !S_IRUSR
|
|
132 # if S_IREAD
|
|
133 # define S_IRUSR S_IREAD
|
|
134 # else
|
|
135 # define S_IRUSR 00400
|
|
136 # endif
|
|
137 #endif
|
|
138
|
|
139 #if !S_IWUSR
|
|
140 # if S_IWRITE
|
|
141 # define S_IWUSR S_IWRITE
|
|
142 # else
|
|
143 # define S_IWUSR 00200
|
|
144 # endif
|
|
145 #endif
|
|
146
|
|
147 #if !S_IXUSR
|
|
148 # if S_IEXEC
|
|
149 # define S_IXUSR S_IEXEC
|
|
150 # else
|
|
151 # define S_IXUSR 00100
|
|
152 # endif
|
|
153 #endif
|
|
154
|
|
155 #ifdef STAT_MACROS_BROKEN
|
|
156 #undef S_ISBLK
|
|
157 #undef S_ISCHR
|
|
158 #undef S_ISDIR
|
|
159 #undef S_ISFIFO
|
|
160 #undef S_ISLNK
|
|
161 #undef S_ISMPB
|
|
162 #undef S_ISMPC
|
|
163 #undef S_ISNWK
|
|
164 #undef S_ISREG
|
|
165 #undef S_ISSOCK
|
|
166 #endif /* STAT_MACROS_BROKEN. */
|
|
167
|
|
168 #if !defined(S_ISBLK) && defined(S_IFBLK)
|
|
169 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
|
170 #endif
|
|
171 #if !defined(S_ISCHR) && defined(S_IFCHR)
|
|
172 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
|
173 #endif
|
|
174 #if !defined(S_ISDIR) && defined(S_IFDIR)
|
|
175 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
176 #endif
|
|
177 #if !defined(S_ISREG) && defined(S_IFREG)
|
|
178 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
179 #endif
|
|
180 #if !defined(S_ISFIFO) && defined(S_IFIFO)
|
|
181 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
|
182 #endif
|
|
183 #if !defined(S_ISLNK) && defined(S_IFLNK)
|
|
184 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
|
185 #endif
|
|
186 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
|
187 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
|
188 #endif
|
|
189 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
|
190 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
|
191 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
|
192 #endif
|
|
193 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
|
194 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
|
195 #endif
|
|
196
|
209
|
197 #if !defined (USG) && !defined (WINDOWSNT)
|
0
|
198 # define HAVE_FSYNC
|
|
199 #endif
|
|
200
|
|
201 #ifndef MAXPATHLEN
|
|
202 /* in 4.1, param.h fails to define this. */
|
|
203 #define MAXPATHLEN 1024
|
|
204 #endif /* not MAXPATHLEN */
|
|
205
|
|
206 #ifndef X_OK
|
|
207 # define X_OK 01
|
|
208 #endif
|
|
209
|
|
210 #ifndef FD_CLOEXEC
|
|
211 # define FD_CLOEXEC 1
|
|
212 #endif
|
|
213
|
|
214 /* encapsulations: file-information calls */
|
|
215
|
|
216 #ifdef ENCAPSULATE_ACCESS
|
|
217 extern int sys_access (CONST char *path, int mode);
|
|
218 #endif
|
|
219 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
|
|
220 # undef access
|
|
221 # define access sys_access
|
|
222 #endif
|
|
223 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
|
|
224 # define sys_access access
|
|
225 #endif
|
|
226
|
2
|
227 #ifdef ENCAPSULATE_EACCESS
|
|
228 extern int sys_eaccess (CONST char *path, int mode);
|
|
229 #endif
|
|
230 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
|
|
231 # undef eaccess
|
|
232 # define eaccess sys_eaccess
|
|
233 #endif
|
|
234 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
|
|
235 # define sys_eaccess eaccess
|
|
236 #endif
|
|
237
|
0
|
238 #ifdef ENCAPSULATE_LSTAT
|
|
239 extern int sys_lstat (CONST char *path, struct stat *buf);
|
|
240 #endif
|
|
241 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
|
|
242 # undef lstat
|
|
243 # define lstat sys_lstat
|
|
244 #endif
|
|
245 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
|
|
246 # define sys_lstat lstat
|
|
247 #endif
|
|
248
|
|
249 #ifdef ENCAPSULATE_READLINK
|
|
250 extern int sys_readlink (CONST char *path, char *buf, int bufsiz);
|
|
251 #endif
|
|
252 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
|
|
253 # undef readlink
|
|
254 # define readlink sys_readlink
|
|
255 #endif
|
|
256 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
|
|
257 # define sys_readlink readlink
|
|
258 #endif
|
|
259
|
|
260 #ifdef ENCAPSULATE_STAT
|
|
261 extern int sys_stat (CONST char *path, struct stat *buf);
|
|
262 #endif
|
|
263 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
|
|
264 # undef stat
|
|
265 /* Need to use arguments to avoid messing with struct stat */
|
|
266 # define stat(path, buf) sys_stat (path, buf)
|
|
267 #endif
|
|
268 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
|
|
269 # define sys_stat stat
|
|
270 #endif
|
|
271
|
|
272 /* encapsulations: file-manipulation calls */
|
|
273
|
|
274 #ifdef ENCAPSULATE_CHMOD
|
|
275 extern int sys_chmod (CONST char *path, int mode);
|
|
276 #endif
|
|
277 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
|
|
278 # undef chmod
|
|
279 # define chmod sys_chmod
|
|
280 #endif
|
|
281 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
|
|
282 # define sys_chmod chmod
|
|
283 #endif
|
|
284
|
|
285 #ifdef ENCAPSULATE_CREAT
|
|
286 extern int sys_creat (CONST char *path, int mode);
|
|
287 #endif
|
|
288 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
|
|
289 # undef creat
|
|
290 # define creat sys_creat
|
|
291 #endif
|
|
292 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
|
|
293 # define sys_creat creat
|
|
294 #endif
|
|
295
|
|
296 #ifdef ENCAPSULATE_LINK
|
|
297 extern int sys_link (CONST char *existing, CONST char *new);
|
|
298 #endif
|
|
299 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
|
|
300 # undef link
|
|
301 # define link sys_link
|
|
302 #endif
|
|
303 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
|
|
304 # define sys_link link
|
|
305 #endif
|
|
306
|
|
307 #ifdef ENCAPSULATE_RENAME
|
|
308 extern int sys_rename (CONST char *old, CONST char *new);
|
|
309 #endif
|
|
310 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
|
|
311 # undef rename
|
|
312 # define rename sys_rename
|
|
313 #endif
|
|
314 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
|
|
315 # define sys_rename rename
|
|
316 #endif
|
|
317
|
|
318 #ifdef ENCAPSULATE_SYMLINK
|
|
319 extern int sys_symlink (CONST char *name1, CONST char *name2);
|
|
320 #endif
|
|
321 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
|
|
322 # undef symlink
|
|
323 # define symlink sys_symlink
|
|
324 #endif
|
|
325 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
|
|
326 # define sys_symlink symlink
|
|
327 #endif
|
|
328
|
|
329 #ifdef ENCAPSULATE_UNLINK
|
|
330 extern int sys_unlink (CONST char *path);
|
|
331 #endif
|
|
332 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
|
|
333 # undef unlink
|
|
334 # define unlink sys_unlink
|
|
335 #endif
|
|
336 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
|
|
337 # define sys_unlink unlink
|
|
338 #endif
|
16
|
339
|
|
340 #ifdef ENCAPSULATE_EXECVP
|
|
341 extern int sys_execvp (CONST char *, char * CONST *);
|
|
342 #endif
|
|
343 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
|
|
344 # undef execvp
|
|
345 # define execvp sys_execvp
|
|
346 #endif
|
|
347 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
|
|
348 # define sys_execvp execvp
|
|
349 #endif
|