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
|
|
38 #if NeXT
|
|
39 /* what is needed from here? Do others need it too? */
|
|
40 # include <sys/fcntl.h>
|
|
41 #endif /* NeXT */
|
|
42
|
|
43 #ifdef VMS
|
|
44 #ifndef __GNUC__
|
|
45 #include <file.h>
|
|
46 #endif
|
|
47 #include <rms.h>
|
|
48 #include <rmsdef.h>
|
|
49 #include <fab.h>
|
|
50 #include <nam.h>
|
|
51 #include <perror.h>
|
|
52 #include <stddef.h>
|
|
53 #endif
|
|
54
|
|
55 #ifdef WINDOWSNT
|
100
|
56 #include <io.h>
|
|
57 #endif
|
|
58
|
|
59 #if 0
|
|
60 #ifdef WINDOWSNT
|
0
|
61 #include <windows.h>
|
|
62 #include <stdlib.h> /* for proper declaration of environ */
|
|
63 #include <fcntl.h>
|
|
64 #include "nt.h"
|
|
65 #define _P_NOWAIT 1 /* from process.h */
|
|
66 #endif
|
100
|
67 #endif
|
0
|
68
|
|
69 #ifdef MSDOS
|
|
70 #include <dos.h>
|
|
71 #include "msdos.h"
|
|
72 #endif /* MSDOS */
|
|
73
|
|
74 #ifndef O_RDONLY
|
|
75 #define O_RDONLY 0
|
|
76 #endif
|
|
77
|
|
78 #ifndef O_WRONLY
|
|
79 #define O_WRONLY 1
|
|
80 #endif
|
|
81
|
|
82 #ifndef O_RDWR
|
|
83 #define O_RDWR 2
|
|
84 #endif
|
|
85
|
|
86 /* if system does not have symbolic links, it does not have lstat.
|
|
87 In that case, use ordinary stat instead. */
|
|
88
|
|
89 #ifndef S_IFLNK
|
|
90 #define lstat stat
|
|
91 #endif
|
|
92
|
|
93 #if !S_IRUSR
|
|
94 # if S_IREAD
|
|
95 # define S_IRUSR S_IREAD
|
|
96 # else
|
|
97 # define S_IRUSR 00400
|
|
98 # endif
|
|
99 #endif
|
|
100
|
|
101 #if !S_IWUSR
|
|
102 # if S_IWRITE
|
|
103 # define S_IWUSR S_IWRITE
|
|
104 # else
|
|
105 # define S_IWUSR 00200
|
|
106 # endif
|
|
107 #endif
|
|
108
|
|
109 #if !S_IXUSR
|
|
110 # if S_IEXEC
|
|
111 # define S_IXUSR S_IEXEC
|
|
112 # else
|
|
113 # define S_IXUSR 00100
|
|
114 # endif
|
|
115 #endif
|
|
116
|
|
117 #ifdef STAT_MACROS_BROKEN
|
|
118 #undef S_ISBLK
|
|
119 #undef S_ISCHR
|
|
120 #undef S_ISDIR
|
|
121 #undef S_ISFIFO
|
|
122 #undef S_ISLNK
|
|
123 #undef S_ISMPB
|
|
124 #undef S_ISMPC
|
|
125 #undef S_ISNWK
|
|
126 #undef S_ISREG
|
|
127 #undef S_ISSOCK
|
|
128 #endif /* STAT_MACROS_BROKEN. */
|
|
129
|
|
130 #if !defined(S_ISBLK) && defined(S_IFBLK)
|
|
131 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
|
132 #endif
|
|
133 #if !defined(S_ISCHR) && defined(S_IFCHR)
|
|
134 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
|
135 #endif
|
|
136 #if !defined(S_ISDIR) && defined(S_IFDIR)
|
|
137 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
138 #endif
|
|
139 #if !defined(S_ISREG) && defined(S_IFREG)
|
|
140 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
141 #endif
|
|
142 #if !defined(S_ISFIFO) && defined(S_IFIFO)
|
|
143 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
|
144 #endif
|
|
145 #if !defined(S_ISLNK) && defined(S_IFLNK)
|
|
146 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
|
147 #endif
|
|
148 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
|
149 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
|
150 #endif
|
|
151 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
|
152 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
|
153 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
|
154 #endif
|
|
155 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
|
156 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
|
157 #endif
|
|
158
|
|
159 #if !defined (USG) && !defined (VMS) && !defined (WINDOWSNT)
|
|
160 # define HAVE_FSYNC
|
|
161 #endif
|
|
162
|
|
163 #ifndef MAXPATHLEN
|
|
164 /* in 4.1, param.h fails to define this. */
|
|
165 #define MAXPATHLEN 1024
|
|
166 #endif /* not MAXPATHLEN */
|
|
167
|
|
168 #ifndef X_OK
|
|
169 # define X_OK 01
|
|
170 #endif
|
|
171
|
|
172 #ifndef FD_CLOEXEC
|
|
173 # define FD_CLOEXEC 1
|
|
174 #endif
|
|
175
|
|
176 /* encapsulations: file-information calls */
|
|
177
|
|
178 #ifdef ENCAPSULATE_ACCESS
|
|
179 extern int sys_access (CONST char *path, int mode);
|
|
180 #endif
|
|
181 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
|
|
182 # undef access
|
|
183 # define access sys_access
|
|
184 #endif
|
|
185 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
|
|
186 # define sys_access access
|
|
187 #endif
|
|
188
|
2
|
189 #ifdef ENCAPSULATE_EACCESS
|
|
190 extern int sys_eaccess (CONST char *path, int mode);
|
|
191 #endif
|
|
192 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
|
|
193 # undef eaccess
|
|
194 # define eaccess sys_eaccess
|
|
195 #endif
|
|
196 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
|
|
197 # define sys_eaccess eaccess
|
|
198 #endif
|
|
199
|
0
|
200 #ifdef ENCAPSULATE_LSTAT
|
|
201 extern int sys_lstat (CONST char *path, struct stat *buf);
|
|
202 #endif
|
|
203 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
|
|
204 # undef lstat
|
|
205 # define lstat sys_lstat
|
|
206 #endif
|
|
207 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
|
|
208 # define sys_lstat lstat
|
|
209 #endif
|
|
210
|
|
211 #ifdef ENCAPSULATE_READLINK
|
|
212 extern int sys_readlink (CONST char *path, char *buf, int bufsiz);
|
|
213 #endif
|
|
214 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
|
|
215 # undef readlink
|
|
216 # define readlink sys_readlink
|
|
217 #endif
|
|
218 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
|
|
219 # define sys_readlink readlink
|
|
220 #endif
|
|
221
|
|
222 #ifdef ENCAPSULATE_STAT
|
|
223 extern int sys_stat (CONST char *path, struct stat *buf);
|
|
224 #endif
|
|
225 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
|
|
226 # undef stat
|
|
227 /* Need to use arguments to avoid messing with struct stat */
|
|
228 # define stat(path, buf) sys_stat (path, buf)
|
|
229 #endif
|
|
230 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
|
|
231 # define sys_stat stat
|
|
232 #endif
|
|
233
|
|
234 /* encapsulations: file-manipulation calls */
|
|
235
|
|
236 #ifdef ENCAPSULATE_CHMOD
|
|
237 extern int sys_chmod (CONST char *path, int mode);
|
|
238 #endif
|
|
239 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
|
|
240 # undef chmod
|
|
241 # define chmod sys_chmod
|
|
242 #endif
|
|
243 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
|
|
244 # define sys_chmod chmod
|
|
245 #endif
|
|
246
|
|
247 #ifdef ENCAPSULATE_CREAT
|
|
248 extern int sys_creat (CONST char *path, int mode);
|
|
249 #endif
|
|
250 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
|
|
251 # undef creat
|
|
252 # define creat sys_creat
|
|
253 #endif
|
|
254 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
|
|
255 # define sys_creat creat
|
|
256 #endif
|
|
257
|
|
258 #ifdef ENCAPSULATE_LINK
|
|
259 extern int sys_link (CONST char *existing, CONST char *new);
|
|
260 #endif
|
|
261 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
|
|
262 # undef link
|
|
263 # define link sys_link
|
|
264 #endif
|
|
265 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
|
|
266 # define sys_link link
|
|
267 #endif
|
|
268
|
|
269 #ifdef ENCAPSULATE_RENAME
|
|
270 extern int sys_rename (CONST char *old, CONST char *new);
|
|
271 #endif
|
|
272 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
|
|
273 # undef rename
|
|
274 # define rename sys_rename
|
|
275 #endif
|
|
276 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
|
|
277 # define sys_rename rename
|
|
278 #endif
|
|
279
|
|
280 #ifdef ENCAPSULATE_SYMLINK
|
|
281 extern int sys_symlink (CONST char *name1, CONST char *name2);
|
|
282 #endif
|
|
283 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
|
|
284 # undef symlink
|
|
285 # define symlink sys_symlink
|
|
286 #endif
|
|
287 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
|
|
288 # define sys_symlink symlink
|
|
289 #endif
|
|
290
|
|
291 #ifdef ENCAPSULATE_UNLINK
|
|
292 extern int sys_unlink (CONST char *path);
|
|
293 #endif
|
|
294 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
|
|
295 # undef unlink
|
|
296 # define unlink sys_unlink
|
|
297 #endif
|
|
298 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
|
|
299 # define sys_unlink unlink
|
|
300 #endif
|
16
|
301
|
|
302 #ifdef ENCAPSULATE_EXECVP
|
|
303 extern int sys_execvp (CONST char *, char * CONST *);
|
|
304 #endif
|
|
305 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
|
|
306 # undef execvp
|
|
307 # define execvp sys_execvp
|
|
308 #endif
|
|
309 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
|
|
310 # define sys_execvp execvp
|
|
311 #endif
|