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>
70 /* file opening defaults */
73 #define OPEN_BINARY O_BINARY
75 #define OPEN_BINARY (0)
81 #define OPEN_TEXT O_TEXT
89 #define CREAT_MODE (S_IREAD | S_IWRITE)
91 #define CREAT_MODE (0666)
97 #define READ_TEXT "rt"
105 #define READ_BINARY "rb"
107 #define READ_BINARY "r"
113 #define WRITE_BINARY "wb"
115 #define WRITE_BINARY "w"
119 /* if system does not have symbolic links, it does not have lstat.
120 In that case, use ordinary stat instead. */
128 # define S_IRUSR S_IREAD
130 # define S_IRUSR 00400
136 # define S_IWUSR S_IWRITE
138 # define S_IWUSR 00200
144 # define S_IXUSR S_IEXEC
146 # define S_IXUSR 00100
150 #ifdef STAT_MACROS_BROKEN
161 #endif /* STAT_MACROS_BROKEN. */
163 #if !defined(S_ISBLK) && defined(S_IFBLK)
164 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
166 #if !defined(S_ISCHR) && defined(S_IFCHR)
167 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
169 #if !defined(S_ISDIR) && defined(S_IFDIR)
170 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
172 #if !defined(S_ISREG) && defined(S_IFREG)
173 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
175 #if !defined(S_ISFIFO) && defined(S_IFIFO)
176 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
178 #if !defined(S_ISLNK) && defined(S_IFLNK)
179 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
181 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
182 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
184 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
185 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
186 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
188 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
189 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
192 #if !defined (USG) && !defined (WINDOWSNT)
197 /* in 4.1, param.h fails to define this. */
198 #define MAXPATHLEN 1024
199 #endif /* not MAXPATHLEN */
206 # define FD_CLOEXEC 1
209 /* Emacs needs to use its own definitions of certain system calls on
210 some systems (like SunOS 4.1 and USG systems, where the read system
211 call is interruptible but Emacs expects it not to be; and under
212 MULE, where all filenames need to be converted to external format).
213 To do this, we #define read to be sys_read, which is defined in
214 sysdep.c. We first #undef read, in case some system file defines
215 read as a macro. sysdep.c doesn't encapsulate read, so the call to
216 read inside of sys_read will do the right thing.
218 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
219 call the actual system calls rather than the encapsulated versions.
220 Those files can call sys_read to get the (possibly) encapsulated
223 IMPORTANT: the redefinition of the system call must occur *after* the
224 inclusion of any header files that declare or define the system call;
225 otherwise lots of unfriendly things can happen. This goes for all
226 encapsulated system calls.
228 We encapsulate the most common system calls here; we assume their
229 declarations are in one of the standard header files included above.
230 Other encapsulations are declared in the appropriate sys*.h file. */
232 #ifdef ENCAPSULATE_READ
233 int sys_read (int, void *, size_t);
235 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
237 # define read sys_read
239 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
240 # define sys_read read
243 #ifdef ENCAPSULATE_WRITE
244 int sys_write (int, CONST void *, size_t);
246 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
248 # define write sys_write
250 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
251 # define sys_write write
254 #ifdef ENCAPSULATE_OPEN
255 int sys_open (CONST char *, int, ...);
257 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
259 # define open sys_open
261 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
262 # define sys_open open
265 #ifdef ENCAPSULATE_CLOSE
268 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
270 # define close sys_close
272 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
273 # define sys_close close
276 /* Now the stdio versions ... */
278 #ifdef ENCAPSULATE_FREAD
279 size_t sys_fread (void *, size_t, size_t, FILE *);
281 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
283 # define fread sys_fread
285 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
286 # define sys_fread fread
289 #ifdef ENCAPSULATE_FWRITE
290 size_t sys_fwrite (CONST void *, size_t, size_t, FILE *);
292 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
294 # define fwrite sys_fwrite
296 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
297 # define sys_fwrite fwrite
300 #ifdef ENCAPSULATE_FOPEN
301 FILE *sys_fopen (CONST char *, CONST char *);
303 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
305 # define fopen sys_fopen
307 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
308 # define sys_fopen fopen
311 #ifdef ENCAPSULATE_FCLOSE
312 int sys_fclose (FILE *);
314 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
316 # define fclose sys_fclose
318 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
319 # define sys_fclose fclose
323 /* encapsulations: file-information calls */
325 #ifdef ENCAPSULATE_ACCESS
326 int sys_access (CONST char *path, int mode);
328 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
330 # define access sys_access
332 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
333 # define sys_access access
336 #ifdef ENCAPSULATE_EACCESS
337 int sys_eaccess (CONST char *path, int mode);
339 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
341 # define eaccess sys_eaccess
343 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
344 # define sys_eaccess eaccess
347 #ifdef ENCAPSULATE_LSTAT
348 int sys_lstat (CONST char *path, struct stat *buf);
350 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
352 # define lstat sys_lstat
354 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
355 # define sys_lstat lstat
358 #ifdef ENCAPSULATE_READLINK
359 int sys_readlink (CONST char *path, char *buf, size_t bufsiz);
361 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
363 # define readlink sys_readlink
365 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
366 # define sys_readlink readlink
369 #ifdef ENCAPSULATE_STAT
370 int sys_stat (CONST char *path, struct stat *buf);
372 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
374 /* Need to use arguments to avoid messing with struct stat */
375 # define stat(path, buf) sys_stat (path, buf)
377 #if !defined (ENCAPSULATE_STAT) && defined (DONT_ENCAPSULATE)
378 # define sys_stat stat
381 /* encapsulations: file-manipulation calls */
383 #ifdef ENCAPSULATE_CHMOD
384 int sys_chmod (CONST char *path, mode_t mode);
386 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
388 # define chmod sys_chmod
390 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
391 # define sys_chmod chmod
394 #ifdef ENCAPSULATE_CREAT
395 int sys_creat (CONST char *path, mode_t mode);
397 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
399 # define creat sys_creat
401 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
402 # define sys_creat creat
405 #ifdef ENCAPSULATE_LINK
406 int sys_link (CONST char *existing, CONST char *new);
408 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
410 # define link sys_link
412 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
413 # define sys_link link
416 #ifdef ENCAPSULATE_RENAME
417 int sys_rename (CONST char *old, CONST char *new);
419 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
421 # define rename sys_rename
423 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
424 # define sys_rename rename
427 #ifdef ENCAPSULATE_SYMLINK
428 int sys_symlink (CONST char *name1, CONST char *name2);
430 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
432 # define symlink sys_symlink
434 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
435 # define sys_symlink symlink
438 #ifdef ENCAPSULATE_UNLINK
439 int sys_unlink (CONST char *path);
441 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
443 # define unlink sys_unlink
445 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
446 # define sys_unlink unlink
449 #ifdef ENCAPSULATE_EXECVP
450 int sys_execvp (CONST char *, char * CONST *);
452 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
454 # define execvp sys_execvp
456 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
457 # define sys_execvp execvp