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 /* Some configuration files' definitions for the LOAD_AVE_CVT macro
55 (like sparc.h's) use macros like FSCALE, defined here. */
61 #include <sys/param.h>
64 #if defined (NeXT) || defined(CYGWIN)
65 /* what is needed from here? Do others need it too?
66 O_BINARY is in here under cygwin. */
67 # include <sys/fcntl.h>
76 #define STDIN_FILENO 0
77 #define STDOUT_FILENO 1
78 #define STDERR_FILENO 2
93 /* file opening defaults */
96 #define OPEN_BINARY O_BINARY
98 #define OPEN_BINARY (0)
104 #define OPEN_TEXT O_TEXT
106 #define OPEN_TEXT (0)
112 #define CREAT_MODE (S_IREAD | S_IWRITE)
114 #define CREAT_MODE (0666)
120 #define READ_TEXT "rt"
122 #define READ_TEXT "r"
128 #define READ_BINARY "rb"
130 #define READ_BINARY "r"
134 #ifndef READ_PLUS_TEXT
136 #define READ_PLUS_TEXT "r+t"
138 #define READ_PLUS_TEXT "r+"
142 #ifndef READ_PLUS_BINARY
144 #define READ_PLUS_BINARY "r+b"
146 #define READ_PLUS_BINARY "r+"
152 #define WRITE_TEXT "wt"
154 #define WRITE_TEXT "w"
160 #define WRITE_BINARY "wb"
162 #define WRITE_BINARY "w"
168 #define O_NONBLOCK O_NDELAY
170 #define O_NONBLOCK 04000
174 /* if system does not have symbolic links, it does not have lstat.
175 In that case, use ordinary stat instead. */
178 #define lstat xemacs_stat
183 # define S_IRUSR S_IREAD
185 # define S_IRUSR 00400
191 # define S_IWUSR S_IWRITE
193 # define S_IWUSR 00200
199 # define S_IXUSR S_IEXEC
201 # define S_IXUSR 00100
205 #ifdef STAT_MACROS_BROKEN
216 #endif /* STAT_MACROS_BROKEN. */
218 #if !defined(S_ISBLK) && defined(S_IFBLK)
219 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
221 #if !defined(S_ISCHR) && defined(S_IFCHR)
222 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
224 #if !defined(S_ISDIR) && defined(S_IFDIR)
225 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
227 #if !defined(S_ISREG) && defined(S_IFREG)
228 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
230 #if !defined(S_ISFIFO) && defined(S_IFIFO)
231 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
233 #if !defined(S_ISLNK) && defined(S_IFLNK)
234 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
236 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
237 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
239 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
240 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
241 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
243 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
244 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
247 /* Client .c files should simply use `PATH_MAX'. */
249 # if defined (_POSIX_PATH_MAX)
250 # define PATH_MAX _POSIX_PATH_MAX
251 # elif defined (MAXPATHLEN)
252 # define PATH_MAX MAXPATHLEN
254 # define PATH_MAX 1024
258 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */
260 # define MAXPATHLEN 1024
263 /* The following definitions are needed under Windows, at least */
268 /* Under native Windows, there is no concept of execute permission,
269 so redefine execute permissions to be the same as read permission */
287 # define FD_CLOEXEC 1
290 /* Emacs needs to use its own definitions of certain system calls on
291 some systems (like SunOS 4.1 and USG systems, where the read system
292 call is interruptible but Emacs expects it not to be; and under
293 MULE, where all filenames need to be converted to external format).
294 To do this, we #define read to be sys_read, which is defined in
295 sysdep.c. We first #undef read, in case some system file defines
296 read as a macro. sysdep.c doesn't encapsulate read, so the call to
297 read inside of sys_read will do the right thing.
299 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
300 call the actual system calls rather than the encapsulated versions.
301 Those files can call sys_read to get the (possibly) encapsulated
304 IMPORTANT: the redefinition of the system call must occur *after* the
305 inclusion of any header files that declare or define the system call;
306 otherwise lots of unfriendly things can happen. This goes for all
307 encapsulated system calls.
309 We encapsulate the most common system calls here; we assume their
310 declarations are in one of the standard header files included above.
311 Other encapsulations are declared in the appropriate sys*.h file. */
313 #ifdef ENCAPSULATE_READ
314 ssize_t sys_read (int, void *, size_t);
316 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
318 # define read sys_read
320 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
321 # define sys_read read
324 #ifdef ENCAPSULATE_WRITE
325 ssize_t sys_write (int, const void *, size_t);
327 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
329 # define write sys_write
331 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
332 # define sys_write write
335 #ifdef ENCAPSULATE_OPEN
336 int sys_open (const char *, int, ...);
338 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
340 # define open sys_open
342 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
343 # define sys_open open
346 #ifdef ENCAPSULATE_CLOSE
349 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
351 # define close sys_close
353 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
354 # define sys_close close
357 /* Now the stdio versions ... */
359 #ifdef ENCAPSULATE_FREAD
360 size_t sys_fread (void *, size_t, size_t, FILE *);
362 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
364 # define fread sys_fread
366 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
367 # define sys_fread fread
370 #ifdef ENCAPSULATE_FWRITE
371 size_t sys_fwrite (const void *, size_t, size_t, FILE *);
373 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
375 # define fwrite sys_fwrite
377 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
378 # define sys_fwrite fwrite
381 #ifdef ENCAPSULATE_FOPEN
382 FILE *sys_fopen (const char *, const char *);
384 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
386 # define fopen sys_fopen
388 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
389 # define sys_fopen fopen
392 #ifdef ENCAPSULATE_FCLOSE
393 int sys_fclose (FILE *);
395 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
397 # define fclose sys_fclose
399 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
400 # define sys_fclose fclose
404 /* encapsulations: file-information calls */
406 #ifdef ENCAPSULATE_ACCESS
407 int sys_access (const char *path, int mode);
409 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
411 # define access sys_access
413 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
414 # define sys_access access
417 #ifdef ENCAPSULATE_EACCESS
418 int sys_eaccess (const char *path, int mode);
420 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
422 # define eaccess sys_eaccess
424 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
425 # define sys_eaccess eaccess
428 #ifdef ENCAPSULATE_LSTAT
429 int sys_lstat (const char *path, struct stat *buf);
431 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
433 # define lstat sys_lstat
435 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
436 # define sys_lstat lstat
439 #ifdef ENCAPSULATE_READLINK
440 int sys_readlink (const char *path, char *buf, size_t bufsiz);
442 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
444 # define readlink sys_readlink
446 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
447 # define sys_readlink readlink
450 #ifdef ENCAPSULATE_FSTAT
451 int sys_fstat (int fd, struct stat *buf);
453 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
455 # define fstat sys_fstat
457 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
458 # define sys_fstat fstat
461 int xemacs_stat (const char *path, struct stat *buf);
463 /* encapsulations: file-manipulation calls */
465 #ifdef ENCAPSULATE_CHMOD
466 int sys_chmod (const char *path, mode_t mode);
468 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
470 # define chmod sys_chmod
472 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
473 # define sys_chmod chmod
476 #ifdef ENCAPSULATE_CREAT
477 int sys_creat (const char *path, mode_t mode);
479 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
481 # define creat sys_creat
483 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
484 # define sys_creat creat
487 #ifdef ENCAPSULATE_LINK
488 int sys_link (const char *existing, const char *new);
490 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
492 # define link sys_link
494 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
495 # define sys_link link
498 #ifdef ENCAPSULATE_RENAME
499 int sys_rename (const char *old, const char *new);
501 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
503 # define rename sys_rename
505 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
506 # define sys_rename rename
509 #ifdef ENCAPSULATE_SYMLINK
510 int sys_symlink (const char *name1, const char *name2);
512 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
514 # define symlink sys_symlink
516 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
517 # define sys_symlink symlink
520 #ifdef ENCAPSULATE_UNLINK
521 int sys_unlink (const char *path);
523 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
525 # define unlink sys_unlink
527 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
528 # define sys_unlink unlink
531 #ifdef ENCAPSULATE_EXECVP
532 int sys_execvp (const char *, char * const *);
534 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
536 # define execvp sys_execvp
538 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
539 # define sys_execvp execvp
542 #endif /* INCLUDED_sysfile_h_ */