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