2 Copyright (C) 1995 Free Software Foundation, Inc.
4 This file is part of XEmacs.
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
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
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. */
21 /* Synched up with: Not really in FSF. */
23 #ifndef INCLUDED_sysfile_h_
24 #define INCLUDED_sysfile_h_
29 #include <sys/errno.h> /* <errno.h> does not always imply this */
36 #ifndef INCLUDED_FCNTL
37 # define INCLUDED_FCNTL
39 #endif /* INCLUDED_FCNTL */
41 /* Load sys/types.h if not already loaded.
42 In some systems loading it twice is suicidal. */
44 #include <sys/types.h> /* some typedefs are used in sys/file.h */
54 #include <sys/param.h>
57 #if defined (NeXT) || defined(CYGWIN)
58 /* what is needed from here? Do others need it too?
59 O_BINARY is in here under cygwin. */
60 # include <sys/fcntl.h>
69 #define STDIN_FILENO 0
70 #define STDOUT_FILENO 1
71 #define STDERR_FILENO 2
86 /* file opening defaults */
89 #define OPEN_BINARY O_BINARY
91 #define OPEN_BINARY (0)
97 #define OPEN_TEXT O_TEXT
105 #define CREAT_MODE (S_IREAD | S_IWRITE)
107 #define CREAT_MODE (0666)
113 #define READ_TEXT "rt"
115 #define READ_TEXT "r"
121 #define READ_BINARY "rb"
123 #define READ_BINARY "r"
127 #ifndef READ_PLUS_TEXT
129 #define READ_PLUS_TEXT "r+t"
131 #define READ_PLUS_TEXT "r+"
135 #ifndef READ_PLUS_BINARY
137 #define READ_PLUS_BINARY "r+b"
139 #define READ_PLUS_BINARY "r+"
145 #define WRITE_TEXT "wt"
147 #define WRITE_TEXT "w"
153 #define WRITE_BINARY "wb"
155 #define WRITE_BINARY "w"
161 #define O_NONBLOCK O_NDELAY
163 #define O_NONBLOCK 04000
167 /* if system does not have symbolic links, it does not have lstat.
168 In that case, use ordinary stat instead. */
176 # define S_IRUSR S_IREAD
178 # define S_IRUSR 00400
184 # define S_IWUSR S_IWRITE
186 # define S_IWUSR 00200
192 # define S_IXUSR S_IEXEC
194 # define S_IXUSR 00100
198 #ifdef STAT_MACROS_BROKEN
209 #endif /* STAT_MACROS_BROKEN. */
211 #if !defined(S_ISBLK) && defined(S_IFBLK)
212 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
214 #if !defined(S_ISCHR) && defined(S_IFCHR)
215 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
217 #if !defined(S_ISDIR) && defined(S_IFDIR)
218 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
220 #if !defined(S_ISREG) && defined(S_IFREG)
221 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
223 #if !defined(S_ISFIFO) && defined(S_IFIFO)
224 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
226 #if !defined(S_ISLNK) && defined(S_IFLNK)
227 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
229 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
230 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
232 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
233 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
234 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
236 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
237 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
240 /* Client .c files should simply use `PATH_MAX'. */
242 # if defined (_POSIX_PATH_MAX)
243 # define PATH_MAX _POSIX_PATH_MAX
244 # elif defined (MAXPATHLEN)
245 # define PATH_MAX MAXPATHLEN
247 # define PATH_MAX 1024
251 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */
253 # define MAXPATHLEN 1024
256 /* The following definitions are needed under Windows, at least */
274 # define FD_CLOEXEC 1
277 /* Emacs needs to use its own definitions of certain system calls on
278 some systems (like SunOS 4.1 and USG systems, where the read system
279 call is interruptible but Emacs expects it not to be; and under
280 MULE, where all filenames need to be converted to external format).
281 To do this, we #define read to be sys_read, which is defined in
282 sysdep.c. We first #undef read, in case some system file defines
283 read as a macro. sysdep.c doesn't encapsulate read, so the call to
284 read inside of sys_read will do the right thing.
286 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
287 call the actual system calls rather than the encapsulated versions.
288 Those files can call sys_read to get the (possibly) encapsulated
291 IMPORTANT: the redefinition of the system call must occur *after* the
292 inclusion of any header files that declare or define the system call;
293 otherwise lots of unfriendly things can happen. This goes for all
294 encapsulated system calls.
296 We encapsulate the most common system calls here; we assume their
297 declarations are in one of the standard header files included above.
298 Other encapsulations are declared in the appropriate sys*.h file. */
300 #ifdef ENCAPSULATE_READ
301 ssize_t sys_read (int, void *, size_t);
303 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
305 # define read sys_read
307 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
308 # define sys_read read
311 #ifdef ENCAPSULATE_WRITE
312 ssize_t sys_write (int, const void *, size_t);
314 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
316 # define write sys_write
318 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
319 # define sys_write write
322 #ifdef ENCAPSULATE_OPEN
323 int sys_open (const char *, int, ...);
325 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
327 # define open sys_open
329 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
330 # define sys_open open
333 #ifdef ENCAPSULATE_CLOSE
336 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
338 # define close sys_close
340 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
341 # define sys_close close
344 /* Now the stdio versions ... */
346 #ifdef ENCAPSULATE_FREAD
347 size_t sys_fread (void *, size_t, size_t, FILE *);
349 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
351 # define fread sys_fread
353 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
354 # define sys_fread fread
357 #ifdef ENCAPSULATE_FWRITE
358 size_t sys_fwrite (const void *, size_t, size_t, FILE *);
360 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
362 # define fwrite sys_fwrite
364 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
365 # define sys_fwrite fwrite
368 #ifdef ENCAPSULATE_FOPEN
369 FILE *sys_fopen (const char *, const char *);
371 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
373 # define fopen sys_fopen
375 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
376 # define sys_fopen fopen
379 #ifdef ENCAPSULATE_FCLOSE
380 int sys_fclose (FILE *);
382 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
384 # define fclose sys_fclose
386 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
387 # define sys_fclose fclose
391 /* encapsulations: file-information calls */
393 #ifdef ENCAPSULATE_ACCESS
394 int sys_access (const char *path, int mode);
396 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
398 # define access sys_access
400 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
401 # define sys_access access
404 #ifdef ENCAPSULATE_EACCESS
405 int sys_eaccess (const char *path, int mode);
407 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
409 # define eaccess sys_eaccess
411 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
412 # define sys_eaccess eaccess
415 #ifdef ENCAPSULATE_LSTAT
416 int sys_lstat (const char *path, struct stat *buf);
418 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
420 # define lstat sys_lstat
422 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
423 # define sys_lstat lstat
426 #ifdef ENCAPSULATE_READLINK
427 int sys_readlink (const char *path, char *buf, size_t bufsiz);
429 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
431 # define readlink sys_readlink
433 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
434 # define sys_readlink readlink
437 #ifdef ENCAPSULATE_FSTAT
438 int sys_fstat (int fd, struct stat *buf);
440 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
442 /* Need to use arguments to avoid messing with struct stat */
443 # define fstat(fd, buf) sys_fstat (fd, buf)
445 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
446 # define sys_fstat fstat
449 #ifdef ENCAPSULATE_STAT
450 int sys_stat (const char *path, struct stat *buf);
452 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
454 /* Need to use arguments to avoid messing with struct stat */
455 # define stat(path, buf) sys_stat (path, buf)
457 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
458 # define sys_stat stat
461 /* encapsulations: file-manipulation calls */
463 #ifdef ENCAPSULATE_CHMOD
464 int sys_chmod (const char *path, mode_t mode);
466 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
468 # define chmod sys_chmod
470 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
471 # define sys_chmod chmod
474 #ifdef ENCAPSULATE_CREAT
475 int sys_creat (const char *path, mode_t mode);
477 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
479 # define creat sys_creat
481 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
482 # define sys_creat creat
485 #ifdef ENCAPSULATE_LINK
486 int sys_link (const char *existing, const char *new);
488 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
490 # define link sys_link
492 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
493 # define sys_link link
496 #ifdef ENCAPSULATE_RENAME
497 int sys_rename (const char *old, const char *new);
499 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
501 # define rename sys_rename
503 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
504 # define sys_rename rename
507 #ifdef ENCAPSULATE_SYMLINK
508 int sys_symlink (const char *name1, const char *name2);
510 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
512 # define symlink sys_symlink
514 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
515 # define sys_symlink symlink
518 #ifdef ENCAPSULATE_UNLINK
519 int sys_unlink (const char *path);
521 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
523 # define unlink sys_unlink
525 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
526 # define sys_unlink unlink
529 #ifdef ENCAPSULATE_EXECVP
530 int sys_execvp (const char *, char * const *);
532 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
534 # define execvp sys_execvp
536 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
537 # define sys_execvp execvp
540 #endif /* INCLUDED_sysfile_h_ */