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
|
398
|
23 #ifndef INCLUDED_sysfile_h_
|
|
24 #define INCLUDED_sysfile_h_
|
|
25
|
0
|
26 #include <errno.h>
|
404
|
27 #include <limits.h>
|
100
|
28
|
|
29 #ifndef WINDOWSNT
|
0
|
30 #include <sys/errno.h> /* <errno.h> does not always imply this */
|
100
|
31 #endif
|
|
32
|
272
|
33 #ifdef HAVE_UNISTD_H
|
|
34 #include <unistd.h>
|
|
35 #endif
|
|
36
|
|
37 #ifndef INCLUDED_FCNTL
|
|
38 # define INCLUDED_FCNTL
|
|
39 # include <fcntl.h>
|
|
40 #endif /* INCLUDED_FCNTL */
|
|
41
|
0
|
42 /* Load sys/types.h if not already loaded.
|
|
43 In some systems loading it twice is suicidal. */
|
|
44 #ifndef makedev
|
|
45 #include <sys/types.h> /* some typedefs are used in sys/file.h */
|
|
46 #endif
|
|
47 #include <sys/file.h>
|
|
48 #include <sys/stat.h>
|
|
49 #include <sys/param.h>
|
|
50
|
251
|
51 #if defined (NeXT) || defined(__CYGWIN32__)
|
272
|
52 /* what is needed from here? Do others need it too?
|
251
|
53 O_BINARY is in here under cygwin. */
|
0
|
54 # include <sys/fcntl.h>
|
|
55 #endif /* NeXT */
|
|
56
|
|
57 #ifdef WINDOWSNT
|
100
|
58 #include <io.h>
|
288
|
59 #include <direct.h>
|
100
|
60 #endif
|
|
61
|
380
|
62 #ifndef STDERR_FILENO
|
|
63 #define STDIN_FILENO 0
|
|
64 #define STDOUT_FILENO 1
|
|
65 #define STDERR_FILENO 2
|
|
66 #endif
|
|
67
|
0
|
68 #ifndef O_RDONLY
|
|
69 #define O_RDONLY 0
|
|
70 #endif
|
|
71
|
|
72 #ifndef O_WRONLY
|
|
73 #define O_WRONLY 1
|
|
74 #endif
|
|
75
|
|
76 #ifndef O_RDWR
|
|
77 #define O_RDWR 2
|
|
78 #endif
|
|
79
|
251
|
80 /* file opening defaults */
|
|
81 #ifndef OPEN_BINARY
|
|
82 #ifdef O_BINARY
|
|
83 #define OPEN_BINARY O_BINARY
|
|
84 #else
|
|
85 #define OPEN_BINARY (0)
|
|
86 #endif
|
|
87 #endif
|
|
88
|
|
89 #ifndef OPEN_TEXT
|
|
90 #ifdef O_TEXT
|
|
91 #define OPEN_TEXT O_TEXT
|
|
92 #else
|
|
93 #define OPEN_TEXT (0)
|
|
94 #endif
|
|
95 #endif
|
|
96
|
|
97 #ifndef CREAT_MODE
|
|
98 #ifdef WINDOWSNT
|
|
99 #define CREAT_MODE (S_IREAD | S_IWRITE)
|
|
100 #else
|
|
101 #define CREAT_MODE (0666)
|
|
102 #endif
|
|
103 #endif
|
|
104
|
|
105 #ifndef READ_TEXT
|
|
106 #ifdef O_TEXT
|
|
107 #define READ_TEXT "rt"
|
|
108 #else
|
|
109 #define READ_TEXT "r"
|
|
110 #endif
|
|
111 #endif
|
|
112
|
|
113 #ifndef READ_BINARY
|
|
114 #ifdef O_BINARY
|
|
115 #define READ_BINARY "rb"
|
|
116 #else
|
|
117 #define READ_BINARY "r"
|
|
118 #endif
|
|
119 #endif
|
|
120
|
|
121 #ifndef WRITE_BINARY
|
|
122 #ifdef O_BINARY
|
|
123 #define WRITE_BINARY "wb"
|
|
124 #else
|
|
125 #define WRITE_BINARY "w"
|
|
126 #endif
|
|
127 #endif
|
|
128
|
380
|
129 #ifndef O_NONBLOCK
|
|
130 #ifdef O_NDELAY
|
|
131 #define O_NONBLOCK O_NDELAY
|
|
132 #else
|
|
133 #define O_NONBLOCK 04000
|
|
134 #endif
|
|
135 #endif
|
|
136
|
0
|
137 /* if system does not have symbolic links, it does not have lstat.
|
|
138 In that case, use ordinary stat instead. */
|
|
139
|
|
140 #ifndef S_IFLNK
|
|
141 #define lstat stat
|
|
142 #endif
|
|
143
|
|
144 #if !S_IRUSR
|
|
145 # if S_IREAD
|
|
146 # define S_IRUSR S_IREAD
|
|
147 # else
|
|
148 # define S_IRUSR 00400
|
|
149 # endif
|
|
150 #endif
|
|
151
|
|
152 #if !S_IWUSR
|
|
153 # if S_IWRITE
|
|
154 # define S_IWUSR S_IWRITE
|
|
155 # else
|
|
156 # define S_IWUSR 00200
|
|
157 # endif
|
|
158 #endif
|
|
159
|
|
160 #if !S_IXUSR
|
|
161 # if S_IEXEC
|
|
162 # define S_IXUSR S_IEXEC
|
|
163 # else
|
|
164 # define S_IXUSR 00100
|
|
165 # endif
|
|
166 #endif
|
|
167
|
|
168 #ifdef STAT_MACROS_BROKEN
|
|
169 #undef S_ISBLK
|
|
170 #undef S_ISCHR
|
|
171 #undef S_ISDIR
|
|
172 #undef S_ISFIFO
|
|
173 #undef S_ISLNK
|
|
174 #undef S_ISMPB
|
|
175 #undef S_ISMPC
|
|
176 #undef S_ISNWK
|
|
177 #undef S_ISREG
|
|
178 #undef S_ISSOCK
|
|
179 #endif /* STAT_MACROS_BROKEN. */
|
|
180
|
|
181 #if !defined(S_ISBLK) && defined(S_IFBLK)
|
|
182 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
|
183 #endif
|
|
184 #if !defined(S_ISCHR) && defined(S_IFCHR)
|
|
185 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
|
186 #endif
|
|
187 #if !defined(S_ISDIR) && defined(S_IFDIR)
|
|
188 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
189 #endif
|
|
190 #if !defined(S_ISREG) && defined(S_IFREG)
|
|
191 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
192 #endif
|
|
193 #if !defined(S_ISFIFO) && defined(S_IFIFO)
|
|
194 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
|
195 #endif
|
|
196 #if !defined(S_ISLNK) && defined(S_IFLNK)
|
|
197 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
|
198 #endif
|
|
199 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
|
200 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
|
201 #endif
|
|
202 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
|
203 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
|
204 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
|
205 #endif
|
|
206 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
|
207 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
|
208 #endif
|
|
209
|
404
|
210 /* Client .c files should simply use `PATH_MAX'. */
|
|
211 #ifndef PATH_MAX
|
|
212 # if defined (_POSIX_PATH_MAX)
|
|
213 # define PATH_MAX _POSIX_PATH_MAX
|
|
214 # elif defined (MAXPATHLEN)
|
|
215 # define PATH_MAX MAXPATHLEN
|
|
216 # else
|
|
217 # define PATH_MAX 1024
|
|
218 # endif
|
|
219 #endif
|
|
220
|
|
221 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */
|
0
|
222 #ifndef MAXPATHLEN
|
404
|
223 # define MAXPATHLEN 1024
|
|
224 #endif
|
0
|
225
|
|
226 #ifndef X_OK
|
|
227 # define X_OK 01
|
|
228 #endif
|
|
229
|
|
230 #ifndef FD_CLOEXEC
|
|
231 # define FD_CLOEXEC 1
|
|
232 #endif
|
|
233
|
272
|
234 /* Emacs needs to use its own definitions of certain system calls on
|
|
235 some systems (like SunOS 4.1 and USG systems, where the read system
|
|
236 call is interruptible but Emacs expects it not to be; and under
|
|
237 MULE, where all filenames need to be converted to external format).
|
|
238 To do this, we #define read to be sys_read, which is defined in
|
|
239 sysdep.c. We first #undef read, in case some system file defines
|
|
240 read as a macro. sysdep.c doesn't encapsulate read, so the call to
|
|
241 read inside of sys_read will do the right thing.
|
|
242
|
|
243 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
|
|
244 call the actual system calls rather than the encapsulated versions.
|
|
245 Those files can call sys_read to get the (possibly) encapsulated
|
|
246 versions.
|
|
247
|
|
248 IMPORTANT: the redefinition of the system call must occur *after* the
|
|
249 inclusion of any header files that declare or define the system call;
|
|
250 otherwise lots of unfriendly things can happen. This goes for all
|
|
251 encapsulated system calls.
|
|
252
|
|
253 We encapsulate the most common system calls here; we assume their
|
|
254 declarations are in one of the standard header files included above.
|
|
255 Other encapsulations are declared in the appropriate sys*.h file. */
|
|
256
|
|
257 #ifdef ENCAPSULATE_READ
|
398
|
258 ssize_t sys_read (int, void *, size_t);
|
272
|
259 #endif
|
|
260 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
|
|
261 # undef read
|
|
262 # define read sys_read
|
|
263 #endif
|
|
264 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
|
|
265 # define sys_read read
|
|
266 #endif
|
|
267
|
|
268 #ifdef ENCAPSULATE_WRITE
|
398
|
269 ssize_t sys_write (int, const void *, size_t);
|
272
|
270 #endif
|
|
271 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
|
|
272 # undef write
|
|
273 # define write sys_write
|
|
274 #endif
|
|
275 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
|
|
276 # define sys_write write
|
|
277 #endif
|
|
278
|
|
279 #ifdef ENCAPSULATE_OPEN
|
398
|
280 int sys_open (const char *, int, ...);
|
272
|
281 #endif
|
|
282 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
|
|
283 # undef open
|
|
284 # define open sys_open
|
|
285 #endif
|
|
286 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
|
|
287 # define sys_open open
|
|
288 #endif
|
|
289
|
|
290 #ifdef ENCAPSULATE_CLOSE
|
|
291 int sys_close (int);
|
|
292 #endif
|
|
293 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
|
|
294 # undef close
|
|
295 # define close sys_close
|
|
296 #endif
|
|
297 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
|
|
298 # define sys_close close
|
|
299 #endif
|
|
300
|
|
301 /* Now the stdio versions ... */
|
|
302
|
|
303 #ifdef ENCAPSULATE_FREAD
|
|
304 size_t sys_fread (void *, size_t, size_t, FILE *);
|
|
305 #endif
|
|
306 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
|
|
307 # undef fread
|
|
308 # define fread sys_fread
|
|
309 #endif
|
|
310 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
|
|
311 # define sys_fread fread
|
|
312 #endif
|
|
313
|
|
314 #ifdef ENCAPSULATE_FWRITE
|
398
|
315 size_t sys_fwrite (const void *, size_t, size_t, FILE *);
|
272
|
316 #endif
|
|
317 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
|
|
318 # undef fwrite
|
|
319 # define fwrite sys_fwrite
|
|
320 #endif
|
|
321 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
|
|
322 # define sys_fwrite fwrite
|
|
323 #endif
|
|
324
|
|
325 #ifdef ENCAPSULATE_FOPEN
|
398
|
326 FILE *sys_fopen (const char *, const char *);
|
272
|
327 #endif
|
|
328 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
|
|
329 # undef fopen
|
|
330 # define fopen sys_fopen
|
|
331 #endif
|
|
332 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
|
|
333 # define sys_fopen fopen
|
|
334 #endif
|
|
335
|
|
336 #ifdef ENCAPSULATE_FCLOSE
|
|
337 int sys_fclose (FILE *);
|
|
338 #endif
|
|
339 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
|
|
340 # undef fclose
|
|
341 # define fclose sys_fclose
|
|
342 #endif
|
|
343 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
|
|
344 # define sys_fclose fclose
|
|
345 #endif
|
|
346
|
|
347
|
0
|
348 /* encapsulations: file-information calls */
|
|
349
|
|
350 #ifdef ENCAPSULATE_ACCESS
|
398
|
351 int sys_access (const char *path, int mode);
|
0
|
352 #endif
|
|
353 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
|
|
354 # undef access
|
|
355 # define access sys_access
|
|
356 #endif
|
|
357 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
|
|
358 # define sys_access access
|
|
359 #endif
|
|
360
|
2
|
361 #ifdef ENCAPSULATE_EACCESS
|
398
|
362 int sys_eaccess (const char *path, int mode);
|
2
|
363 #endif
|
|
364 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
|
|
365 # undef eaccess
|
|
366 # define eaccess sys_eaccess
|
|
367 #endif
|
|
368 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
|
|
369 # define sys_eaccess eaccess
|
|
370 #endif
|
|
371
|
0
|
372 #ifdef ENCAPSULATE_LSTAT
|
398
|
373 int sys_lstat (const char *path, struct stat *buf);
|
0
|
374 #endif
|
|
375 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
|
|
376 # undef lstat
|
|
377 # define lstat sys_lstat
|
|
378 #endif
|
|
379 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
|
|
380 # define sys_lstat lstat
|
|
381 #endif
|
|
382
|
|
383 #ifdef ENCAPSULATE_READLINK
|
398
|
384 int sys_readlink (const char *path, char *buf, size_t bufsiz);
|
0
|
385 #endif
|
|
386 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
|
|
387 # undef readlink
|
|
388 # define readlink sys_readlink
|
|
389 #endif
|
|
390 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
|
|
391 # define sys_readlink readlink
|
|
392 #endif
|
|
393
|
398
|
394 #ifdef ENCAPSULATE_FSTAT
|
|
395 int sys_fstat (int fd, struct stat *buf);
|
|
396 #endif
|
|
397 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
|
|
398 # undef fstat
|
|
399 /* Need to use arguments to avoid messing with struct stat */
|
|
400 # define fstat(fd, buf) sys_fstat (fd, buf)
|
|
401 #endif
|
|
402 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
|
|
403 # define sys_fstat fstat
|
|
404 #endif
|
|
405
|
0
|
406 #ifdef ENCAPSULATE_STAT
|
398
|
407 int sys_stat (const char *path, struct stat *buf);
|
0
|
408 #endif
|
|
409 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
|
|
410 # undef stat
|
|
411 /* Need to use arguments to avoid messing with struct stat */
|
|
412 # define stat(path, buf) sys_stat (path, buf)
|
|
413 #endif
|
|
414 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
|
|
415 # define sys_stat stat
|
|
416 #endif
|
|
417
|
|
418 /* encapsulations: file-manipulation calls */
|
|
419
|
|
420 #ifdef ENCAPSULATE_CHMOD
|
398
|
421 int sys_chmod (const char *path, mode_t mode);
|
0
|
422 #endif
|
|
423 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
|
|
424 # undef chmod
|
|
425 # define chmod sys_chmod
|
|
426 #endif
|
|
427 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
|
|
428 # define sys_chmod chmod
|
|
429 #endif
|
|
430
|
|
431 #ifdef ENCAPSULATE_CREAT
|
398
|
432 int sys_creat (const char *path, mode_t mode);
|
0
|
433 #endif
|
|
434 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
|
|
435 # undef creat
|
|
436 # define creat sys_creat
|
|
437 #endif
|
|
438 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
|
|
439 # define sys_creat creat
|
|
440 #endif
|
|
441
|
|
442 #ifdef ENCAPSULATE_LINK
|
398
|
443 int sys_link (const char *existing, const char *new);
|
0
|
444 #endif
|
|
445 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
|
|
446 # undef link
|
|
447 # define link sys_link
|
|
448 #endif
|
|
449 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
|
|
450 # define sys_link link
|
|
451 #endif
|
|
452
|
|
453 #ifdef ENCAPSULATE_RENAME
|
398
|
454 int sys_rename (const char *old, const char *new);
|
0
|
455 #endif
|
|
456 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
|
|
457 # undef rename
|
|
458 # define rename sys_rename
|
|
459 #endif
|
|
460 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
|
|
461 # define sys_rename rename
|
|
462 #endif
|
|
463
|
|
464 #ifdef ENCAPSULATE_SYMLINK
|
398
|
465 int sys_symlink (const char *name1, const char *name2);
|
0
|
466 #endif
|
|
467 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
|
|
468 # undef symlink
|
|
469 # define symlink sys_symlink
|
|
470 #endif
|
|
471 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
|
|
472 # define sys_symlink symlink
|
|
473 #endif
|
|
474
|
|
475 #ifdef ENCAPSULATE_UNLINK
|
398
|
476 int sys_unlink (const char *path);
|
0
|
477 #endif
|
|
478 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
|
|
479 # undef unlink
|
|
480 # define unlink sys_unlink
|
|
481 #endif
|
|
482 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
|
|
483 # define sys_unlink unlink
|
|
484 #endif
|
16
|
485
|
|
486 #ifdef ENCAPSULATE_EXECVP
|
398
|
487 int sys_execvp (const char *, char * const *);
|
16
|
488 #endif
|
|
489 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
|
|
490 # undef execvp
|
|
491 # define execvp sys_execvp
|
|
492 #endif
|
|
493 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
|
|
494 # define sys_execvp execvp
|
|
495 #endif
|
398
|
496
|
|
497 #endif /* INCLUDED_sysfile_h_ */
|