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