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)
207 /* in 4.1, param.h fails to define this. */
208 #define MAXPATHLEN 1024
209 #endif /* not MAXPATHLEN */
216 # define FD_CLOEXEC 1
219 /* Emacs needs to use its own definitions of certain system calls on
220 some systems (like SunOS 4.1 and USG systems, where the read system
221 call is interruptible but Emacs expects it not to be; and under
222 MULE, where all filenames need to be converted to external format).
223 To do this, we #define read to be sys_read, which is defined in
224 sysdep.c. We first #undef read, in case some system file defines
225 read as a macro. sysdep.c doesn't encapsulate read, so the call to
226 read inside of sys_read will do the right thing.
228 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
229 call the actual system calls rather than the encapsulated versions.
230 Those files can call sys_read to get the (possibly) encapsulated
233 IMPORTANT: the redefinition of the system call must occur *after* the
234 inclusion of any header files that declare or define the system call;
235 otherwise lots of unfriendly things can happen. This goes for all
236 encapsulated system calls.
238 We encapsulate the most common system calls here; we assume their
239 declarations are in one of the standard header files included above.
240 Other encapsulations are declared in the appropriate sys*.h file. */
242 #ifdef ENCAPSULATE_READ
243 ssize_t sys_read (int, void *, size_t);
245 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
247 # define read sys_read
249 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
250 # define sys_read read
253 #ifdef ENCAPSULATE_WRITE
254 ssize_t sys_write (int, CONST void *, size_t);
256 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
258 # define write sys_write
260 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
261 # define sys_write write
264 #ifdef ENCAPSULATE_OPEN
265 int sys_open (CONST char *, int, ...);
267 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
269 # define open sys_open
271 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
272 # define sys_open open
275 #ifdef ENCAPSULATE_CLOSE
278 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
280 # define close sys_close
282 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
283 # define sys_close close
286 /* Now the stdio versions ... */
288 #ifdef ENCAPSULATE_FREAD
289 size_t sys_fread (void *, size_t, size_t, FILE *);
291 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
293 # define fread sys_fread
295 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
296 # define sys_fread fread
299 #ifdef ENCAPSULATE_FWRITE
300 size_t sys_fwrite (CONST void *, size_t, size_t, FILE *);
302 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
304 # define fwrite sys_fwrite
306 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
307 # define sys_fwrite fwrite
310 #ifdef ENCAPSULATE_FOPEN
311 FILE *sys_fopen (CONST char *, CONST char *);
313 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
315 # define fopen sys_fopen
317 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
318 # define sys_fopen fopen
321 #ifdef ENCAPSULATE_FCLOSE
322 int sys_fclose (FILE *);
324 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
326 # define fclose sys_fclose
328 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
329 # define sys_fclose fclose
333 /* encapsulations: file-information calls */
335 #ifdef ENCAPSULATE_ACCESS
336 int sys_access (CONST char *path, int mode);
338 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
340 # define access sys_access
342 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
343 # define sys_access access
346 #ifdef ENCAPSULATE_EACCESS
347 int sys_eaccess (CONST char *path, int mode);
349 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
351 # define eaccess sys_eaccess
353 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
354 # define sys_eaccess eaccess
357 #ifdef ENCAPSULATE_LSTAT
358 int sys_lstat (CONST char *path, struct stat *buf);
360 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
362 # define lstat sys_lstat
364 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
365 # define sys_lstat lstat
368 #ifdef ENCAPSULATE_READLINK
369 int sys_readlink (CONST char *path, char *buf, size_t bufsiz);
371 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
373 # define readlink sys_readlink
375 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
376 # define sys_readlink readlink
379 #ifdef ENCAPSULATE_FSTAT
380 int sys_fstat (int fd, struct stat *buf);
382 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
384 /* Need to use arguments to avoid messing with struct stat */
385 # define fstat(fd, buf) sys_fstat (fd, buf)
387 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
388 # define sys_fstat fstat
391 #ifdef ENCAPSULATE_STAT
392 int sys_stat (CONST char *path, struct stat *buf);
394 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
396 /* Need to use arguments to avoid messing with struct stat */
397 # define stat(path, buf) sys_stat (path, buf)
399 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
400 # define sys_stat stat
403 /* encapsulations: file-manipulation calls */
405 #ifdef ENCAPSULATE_CHMOD
406 int sys_chmod (CONST char *path, mode_t mode);
408 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
410 # define chmod sys_chmod
412 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
413 # define sys_chmod chmod
416 #ifdef ENCAPSULATE_CREAT
417 int sys_creat (CONST char *path, mode_t mode);
419 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
421 # define creat sys_creat
423 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
424 # define sys_creat creat
427 #ifdef ENCAPSULATE_LINK
428 int sys_link (CONST char *existing, CONST char *new);
430 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
432 # define link sys_link
434 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
435 # define sys_link link
438 #ifdef ENCAPSULATE_RENAME
439 int sys_rename (CONST char *old, CONST char *new);
441 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
443 # define rename sys_rename
445 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
446 # define sys_rename rename
449 #ifdef ENCAPSULATE_SYMLINK
450 int sys_symlink (CONST char *name1, CONST char *name2);
452 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
454 # define symlink sys_symlink
456 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
457 # define sys_symlink symlink
460 #ifdef ENCAPSULATE_UNLINK
461 int sys_unlink (CONST char *path);
463 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
465 # define unlink sys_unlink
467 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
468 # define sys_unlink unlink
471 #ifdef ENCAPSULATE_EXECVP
472 int sys_execvp (CONST char *, char * CONST *);
474 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
476 # define execvp sys_execvp
478 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
479 # define sys_execvp execvp