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. */
26 #include <sys/errno.h> /* <errno.h> does not always imply this */
33 #ifndef INCLUDED_FCNTL
34 # define INCLUDED_FCNTL
36 #endif /* INCLUDED_FCNTL */
38 /* Load sys/types.h if not already loaded.
39 In some systems loading it twice is suicidal. */
41 #include <sys/types.h> /* some typedefs are used in sys/file.h */
45 #include <sys/param.h>
47 #if defined (NeXT) || defined(__CYGWIN32__)
48 /* what is needed from here? Do others need it too?
49 O_BINARY is in here under cygwin. */
50 # include <sys/fcntl.h>
59 #define STDIN_FILENO 0
60 #define STDOUT_FILENO 1
61 #define STDERR_FILENO 2
76 /* file opening defaults */
79 #define OPEN_BINARY O_BINARY
81 #define OPEN_BINARY (0)
87 #define OPEN_TEXT O_TEXT
95 #define CREAT_MODE (S_IREAD | S_IWRITE)
97 #define CREAT_MODE (0666)
103 #define READ_TEXT "rt"
105 #define READ_TEXT "r"
111 #define READ_BINARY "rb"
113 #define READ_BINARY "r"
119 #define WRITE_BINARY "wb"
121 #define WRITE_BINARY "w"
127 #define O_NONBLOCK O_NDELAY
129 #define O_NONBLOCK 04000
133 /* if system does not have symbolic links, it does not have lstat.
134 In that case, use ordinary stat instead. */
142 # define S_IRUSR S_IREAD
144 # define S_IRUSR 00400
150 # define S_IWUSR S_IWRITE
152 # define S_IWUSR 00200
158 # define S_IXUSR S_IEXEC
160 # define S_IXUSR 00100
164 #ifdef STAT_MACROS_BROKEN
175 #endif /* STAT_MACROS_BROKEN. */
177 #if !defined(S_ISBLK) && defined(S_IFBLK)
178 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
180 #if !defined(S_ISCHR) && defined(S_IFCHR)
181 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
183 #if !defined(S_ISDIR) && defined(S_IFDIR)
184 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
186 #if !defined(S_ISREG) && defined(S_IFREG)
187 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
189 #if !defined(S_ISFIFO) && defined(S_IFIFO)
190 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
192 #if !defined(S_ISLNK) && defined(S_IFLNK)
193 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
195 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
196 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
198 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
199 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
200 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
202 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
203 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
206 #if !defined (USG) && !defined (WINDOWSNT)
211 /* in 4.1, param.h fails to define this. */
212 #define MAXPATHLEN 1024
213 #endif /* not MAXPATHLEN */
220 # define FD_CLOEXEC 1
223 /* Emacs needs to use its own definitions of certain system calls on
224 some systems (like SunOS 4.1 and USG systems, where the read system
225 call is interruptible but Emacs expects it not to be; and under
226 MULE, where all filenames need to be converted to external format).
227 To do this, we #define read to be sys_read, which is defined in
228 sysdep.c. We first #undef read, in case some system file defines
229 read as a macro. sysdep.c doesn't encapsulate read, so the call to
230 read inside of sys_read will do the right thing.
232 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
233 call the actual system calls rather than the encapsulated versions.
234 Those files can call sys_read to get the (possibly) encapsulated
237 IMPORTANT: the redefinition of the system call must occur *after* the
238 inclusion of any header files that declare or define the system call;
239 otherwise lots of unfriendly things can happen. This goes for all
240 encapsulated system calls.
242 We encapsulate the most common system calls here; we assume their
243 declarations are in one of the standard header files included above.
244 Other encapsulations are declared in the appropriate sys*.h file. */
246 #ifdef ENCAPSULATE_READ
247 int sys_read (int, void *, size_t);
249 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
251 # define read sys_read
253 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
254 # define sys_read read
257 #ifdef ENCAPSULATE_WRITE
258 int sys_write (int, CONST void *, size_t);
260 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
262 # define write sys_write
264 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
265 # define sys_write write
268 #ifdef ENCAPSULATE_OPEN
269 int sys_open (CONST char *, int, ...);
271 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
273 # define open sys_open
275 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
276 # define sys_open open
279 #ifdef ENCAPSULATE_CLOSE
282 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
284 # define close sys_close
286 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
287 # define sys_close close
290 /* Now the stdio versions ... */
292 #ifdef ENCAPSULATE_FREAD
293 size_t sys_fread (void *, size_t, size_t, FILE *);
295 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
297 # define fread sys_fread
299 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
300 # define sys_fread fread
303 #ifdef ENCAPSULATE_FWRITE
304 size_t sys_fwrite (CONST void *, size_t, size_t, FILE *);
306 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
308 # define fwrite sys_fwrite
310 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
311 # define sys_fwrite fwrite
314 #ifdef ENCAPSULATE_FOPEN
315 FILE *sys_fopen (CONST char *, CONST char *);
317 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
319 # define fopen sys_fopen
321 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
322 # define sys_fopen fopen
325 #ifdef ENCAPSULATE_FCLOSE
326 int sys_fclose (FILE *);
328 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
330 # define fclose sys_fclose
332 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
333 # define sys_fclose fclose
337 /* encapsulations: file-information calls */
339 #ifdef ENCAPSULATE_ACCESS
340 int sys_access (CONST char *path, int mode);
342 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
344 # define access sys_access
346 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
347 # define sys_access access
350 #ifdef ENCAPSULATE_EACCESS
351 int sys_eaccess (CONST char *path, int mode);
353 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
355 # define eaccess sys_eaccess
357 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
358 # define sys_eaccess eaccess
361 #ifdef ENCAPSULATE_LSTAT
362 int sys_lstat (CONST char *path, struct stat *buf);
364 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
366 # define lstat sys_lstat
368 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
369 # define sys_lstat lstat
372 #ifdef ENCAPSULATE_READLINK
373 int sys_readlink (CONST char *path, char *buf, size_t bufsiz);
375 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
377 # define readlink sys_readlink
379 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
380 # define sys_readlink readlink
383 #ifdef ENCAPSULATE_STAT
384 int sys_stat (CONST char *path, struct stat *buf);
386 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
388 /* Need to use arguments to avoid messing with struct stat */
389 # define stat(path, buf) sys_stat (path, buf)
391 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
392 # define sys_stat stat
395 /* encapsulations: file-manipulation calls */
397 #ifdef ENCAPSULATE_CHMOD
398 int sys_chmod (CONST char *path, mode_t mode);
400 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
402 # define chmod sys_chmod
404 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
405 # define sys_chmod chmod
408 #ifdef ENCAPSULATE_CREAT
409 int sys_creat (CONST char *path, mode_t mode);
411 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
413 # define creat sys_creat
415 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
416 # define sys_creat creat
419 #ifdef ENCAPSULATE_LINK
420 int sys_link (CONST char *existing, CONST char *new);
422 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
424 # define link sys_link
426 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
427 # define sys_link link
430 #ifdef ENCAPSULATE_RENAME
431 int sys_rename (CONST char *old, CONST char *new);
433 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
435 # define rename sys_rename
437 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
438 # define sys_rename rename
441 #ifdef ENCAPSULATE_SYMLINK
442 int sys_symlink (CONST char *name1, CONST char *name2);
444 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
446 # define symlink sys_symlink
448 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
449 # define sys_symlink symlink
452 #ifdef ENCAPSULATE_UNLINK
453 int sys_unlink (CONST char *path);
455 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
457 # define unlink sys_unlink
459 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
460 # define sys_unlink unlink
463 #ifdef ENCAPSULATE_EXECVP
464 int sys_execvp (CONST char *, char * CONST *);
466 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
468 # define execvp sys_execvp
470 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
471 # define sys_execvp execvp