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