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 */
48 #include <sys/param.h>
50 #if defined (NeXT) || defined(__CYGWIN32__)
51 /* what is needed from here? Do others need it too?
52 O_BINARY is in here under cygwin. */
53 # include <sys/fcntl.h>
62 #define STDIN_FILENO 0
63 #define STDOUT_FILENO 1
64 #define STDERR_FILENO 2
79 /* file opening defaults */
82 #define OPEN_BINARY O_BINARY
84 #define OPEN_BINARY (0)
90 #define OPEN_TEXT O_TEXT
98 #define CREAT_MODE (S_IREAD | S_IWRITE)
100 #define CREAT_MODE (0666)
106 #define READ_TEXT "rt"
108 #define READ_TEXT "r"
114 #define READ_BINARY "rb"
116 #define READ_BINARY "r"
122 #define WRITE_BINARY "wb"
124 #define WRITE_BINARY "w"
130 #define O_NONBLOCK O_NDELAY
132 #define O_NONBLOCK 04000
136 /* if system does not have symbolic links, it does not have lstat.
137 In that case, use ordinary stat instead. */
145 # define S_IRUSR S_IREAD
147 # define S_IRUSR 00400
153 # define S_IWUSR S_IWRITE
155 # define S_IWUSR 00200
161 # define S_IXUSR S_IEXEC
163 # define S_IXUSR 00100
167 #ifdef STAT_MACROS_BROKEN
178 #endif /* STAT_MACROS_BROKEN. */
180 #if !defined(S_ISBLK) && defined(S_IFBLK)
181 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
183 #if !defined(S_ISCHR) && defined(S_IFCHR)
184 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
186 #if !defined(S_ISDIR) && defined(S_IFDIR)
187 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
189 #if !defined(S_ISREG) && defined(S_IFREG)
190 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
192 #if !defined(S_ISFIFO) && defined(S_IFIFO)
193 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
195 #if !defined(S_ISLNK) && defined(S_IFLNK)
196 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
198 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
199 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
201 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
202 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
203 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
205 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
206 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
210 /* in 4.1, param.h fails to define this. */
211 #define MAXPATHLEN 1024
212 #endif /* not MAXPATHLEN */
219 # define FD_CLOEXEC 1
222 /* Emacs needs to use its own definitions of certain system calls on
223 some systems (like SunOS 4.1 and USG systems, where the read system
224 call is interruptible but Emacs expects it not to be; and under
225 MULE, where all filenames need to be converted to external format).
226 To do this, we #define read to be sys_read, which is defined in
227 sysdep.c. We first #undef read, in case some system file defines
228 read as a macro. sysdep.c doesn't encapsulate read, so the call to
229 read inside of sys_read will do the right thing.
231 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
232 call the actual system calls rather than the encapsulated versions.
233 Those files can call sys_read to get the (possibly) encapsulated
236 IMPORTANT: the redefinition of the system call must occur *after* the
237 inclusion of any header files that declare or define the system call;
238 otherwise lots of unfriendly things can happen. This goes for all
239 encapsulated system calls.
241 We encapsulate the most common system calls here; we assume their
242 declarations are in one of the standard header files included above.
243 Other encapsulations are declared in the appropriate sys*.h file. */
245 #ifdef ENCAPSULATE_READ
246 ssize_t sys_read (int, void *, size_t);
248 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
250 # define read sys_read
252 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
253 # define sys_read read
256 #ifdef ENCAPSULATE_WRITE
257 ssize_t sys_write (int, const void *, size_t);
259 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
261 # define write sys_write
263 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
264 # define sys_write write
267 #ifdef ENCAPSULATE_OPEN
268 int sys_open (const char *, int, ...);
270 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
272 # define open sys_open
274 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
275 # define sys_open open
278 #ifdef ENCAPSULATE_CLOSE
281 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
283 # define close sys_close
285 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
286 # define sys_close close
289 /* Now the stdio versions ... */
291 #ifdef ENCAPSULATE_FREAD
292 size_t sys_fread (void *, size_t, size_t, FILE *);
294 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
296 # define fread sys_fread
298 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
299 # define sys_fread fread
302 #ifdef ENCAPSULATE_FWRITE
303 size_t sys_fwrite (const void *, size_t, size_t, FILE *);
305 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
307 # define fwrite sys_fwrite
309 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
310 # define sys_fwrite fwrite
313 #ifdef ENCAPSULATE_FOPEN
314 FILE *sys_fopen (const char *, const char *);
316 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
318 # define fopen sys_fopen
320 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
321 # define sys_fopen fopen
324 #ifdef ENCAPSULATE_FCLOSE
325 int sys_fclose (FILE *);
327 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
329 # define fclose sys_fclose
331 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
332 # define sys_fclose fclose
336 /* encapsulations: file-information calls */
338 #ifdef ENCAPSULATE_ACCESS
339 int sys_access (const char *path, int mode);
341 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
343 # define access sys_access
345 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
346 # define sys_access access
349 #ifdef ENCAPSULATE_EACCESS
350 int sys_eaccess (const char *path, int mode);
352 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
354 # define eaccess sys_eaccess
356 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
357 # define sys_eaccess eaccess
360 #ifdef ENCAPSULATE_LSTAT
361 int sys_lstat (const char *path, struct stat *buf);
363 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
365 # define lstat sys_lstat
367 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
368 # define sys_lstat lstat
371 #ifdef ENCAPSULATE_READLINK
372 int sys_readlink (const char *path, char *buf, size_t bufsiz);
374 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
376 # define readlink sys_readlink
378 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
379 # define sys_readlink readlink
382 #ifdef ENCAPSULATE_FSTAT
383 int sys_fstat (int fd, struct stat *buf);
385 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
387 /* Need to use arguments to avoid messing with struct stat */
388 # define fstat(fd, buf) sys_fstat (fd, buf)
390 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
391 # define sys_fstat fstat
394 #ifdef ENCAPSULATE_STAT
395 int sys_stat (const char *path, struct stat *buf);
397 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
399 /* Need to use arguments to avoid messing with struct stat */
400 # define stat(path, buf) sys_stat (path, buf)
402 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
403 # define sys_stat stat
406 /* encapsulations: file-manipulation calls */
408 #ifdef ENCAPSULATE_CHMOD
409 int sys_chmod (const char *path, mode_t mode);
411 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
413 # define chmod sys_chmod
415 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
416 # define sys_chmod chmod
419 #ifdef ENCAPSULATE_CREAT
420 int sys_creat (const char *path, mode_t mode);
422 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
424 # define creat sys_creat
426 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
427 # define sys_creat creat
430 #ifdef ENCAPSULATE_LINK
431 int sys_link (const char *existing, const char *new);
433 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
435 # define link sys_link
437 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
438 # define sys_link link
441 #ifdef ENCAPSULATE_RENAME
442 int sys_rename (const char *old, const char *new);
444 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
446 # define rename sys_rename
448 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
449 # define sys_rename rename
452 #ifdef ENCAPSULATE_SYMLINK
453 int sys_symlink (const char *name1, const char *name2);
455 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
457 # define symlink sys_symlink
459 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
460 # define sys_symlink symlink
463 #ifdef ENCAPSULATE_UNLINK
464 int sys_unlink (const char *path);
466 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
468 # define unlink sys_unlink
470 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
471 # define sys_unlink unlink
474 #ifdef ENCAPSULATE_EXECVP
475 int sys_execvp (const char *, char * const *);
477 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
479 # define execvp sys_execvp
481 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
482 # define sys_execvp execvp
485 #endif /* INCLUDED_sysfile_h_ */