2 Copyright (C) 1995 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: Not really in FSF. */
22 #ifndef INCLUDED_sysfile_h_
23 #define INCLUDED_sysfile_h_
27 #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 */
48 #include <sys/param.h>
51 /* what is needed from here? Do others need it too? */
52 # include <sys/fcntl.h>
56 #define STDIN_FILENO 0
57 #define STDOUT_FILENO 1
58 #define STDERR_FILENO 2
73 /* file opening defaults */
76 #define OPEN_BINARY O_BINARY
78 #define OPEN_BINARY (0)
84 #define OPEN_TEXT O_TEXT
91 #define CREAT_MODE (0666)
96 #define READ_TEXT "rt"
104 #define READ_BINARY "rb"
106 #define READ_BINARY "r"
110 #ifndef READ_PLUS_TEXT
112 #define READ_PLUS_TEXT "r+t"
114 #define READ_PLUS_TEXT "r+"
118 #ifndef READ_PLUS_BINARY
120 #define READ_PLUS_BINARY "r+b"
122 #define READ_PLUS_BINARY "r+"
128 #define WRITE_TEXT "wt"
130 #define WRITE_TEXT "w"
136 #define WRITE_BINARY "wb"
138 #define WRITE_BINARY "w"
144 #define O_NONBLOCK O_NDELAY
146 #define O_NONBLOCK 04000
150 /* if system does not have symbolic links, it does not have lstat.
151 In that case, use ordinary stat instead. */
154 #define lstat sxemacs_stat
159 # define S_IRUSR S_IREAD
161 # define S_IRUSR 00400
167 # define S_IWUSR S_IWRITE
169 # define S_IWUSR 00200
175 # define S_IXUSR S_IEXEC
177 # define S_IXUSR 00100
181 #ifdef STAT_MACROS_BROKEN
192 #endif /* STAT_MACROS_BROKEN. */
194 #if !defined(S_ISBLK) && defined(S_IFBLK)
195 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
197 #if !defined(S_ISCHR) && defined(S_IFCHR)
198 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
200 #if !defined(S_ISDIR) && defined(S_IFDIR)
201 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
203 #if !defined(S_ISREG) && defined(S_IFREG)
204 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
206 #if !defined(S_ISFIFO) && defined(S_IFIFO)
207 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
209 #if !defined(S_ISLNK) && defined(S_IFLNK)
210 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
212 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
213 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
215 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
216 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
217 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
219 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
220 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
223 /* Client .c files should simply use `PATH_MAX'. */
225 # if defined (_POSIX_PATH_MAX)
226 # define PATH_MAX _POSIX_PATH_MAX
227 # elif defined (MAXPATHLEN)
228 # define PATH_MAX MAXPATHLEN
230 # define PATH_MAX 1024
234 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */
236 # define MAXPATHLEN 1024
239 /* The following definitions are needed under Windows, at least */
257 # define FD_CLOEXEC 1
260 /* Emacs needs to use its own definitions of certain system calls on
261 some systems (like SunOS 4.1 and USG systems, where the read system
262 call is interruptible but Emacs expects it not to be; and under
263 MULE, where all filenames need to be converted to external format).
264 To do this, we #define read to be sys_read, which is defined in
265 sysdep.c. We first #undef read, in case some system file defines
266 read as a macro. sysdep.c doesn't encapsulate read, so the call to
267 read inside of sys_read will do the right thing.
269 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
270 call the actual system calls rather than the encapsulated versions.
271 Those files can call sys_read to get the (possibly) encapsulated
274 IMPORTANT: the redefinition of the system call must occur *after* the
275 inclusion of any header files that declare or define the system call;
276 otherwise lots of unfriendly things can happen. This goes for all
277 encapsulated system calls.
279 We encapsulate the most common system calls here; we assume their
280 declarations are in one of the standard header files included above.
281 Other encapsulations are declared in the appropriate sys*.h file. */
283 #ifdef ENCAPSULATE_READ
284 ssize_t sys_read(int, void *, size_t);
286 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
288 # define read sys_read
290 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
291 # define sys_read read
294 #ifdef ENCAPSULATE_WRITE
295 ssize_t sys_write(int, const void *, size_t);
297 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
299 # define write sys_write
301 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
302 # define sys_write write
305 #ifdef ENCAPSULATE_OPEN
306 int sys_open(const char *, int, ...);
307 int raw_open(const char *, int, ...);
309 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
311 # define open sys_open
313 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
314 # define sys_open open
315 # define raw_open open
318 #ifdef ENCAPSULATE_CLOSE
321 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
323 # define close sys_close
325 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
326 # define sys_close close
329 /* Now the stdio versions ... */
331 #ifdef ENCAPSULATE_FREAD
332 size_t sys_fread(void *, size_t, size_t, FILE *);
334 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
336 # define fread sys_fread
338 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
339 # define sys_fread fread
342 #ifdef ENCAPSULATE_FWRITE
343 size_t sys_fwrite(const void *, size_t, size_t, FILE *);
345 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
347 # define fwrite sys_fwrite
349 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
350 # define sys_fwrite fwrite
353 #ifdef ENCAPSULATE_FOPEN
354 FILE *sys_fopen(const char *, const char *);
356 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
358 # define fopen sys_fopen
360 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
361 # define sys_fopen fopen
364 #ifdef ENCAPSULATE_FCLOSE
365 int sys_fclose(FILE *);
367 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
369 # define fclose sys_fclose
371 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
372 # define sys_fclose fclose
375 /* encapsulations: file-information calls */
377 #ifdef ENCAPSULATE_ACCESS
378 int sys_access(const char *path, int mode);
380 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
382 # define access sys_access
384 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
385 # define sys_access access
388 #ifdef ENCAPSULATE_EACCESS
389 int sys_eaccess(const char *path, int mode);
391 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
393 # define eaccess sys_eaccess
395 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
396 # define sys_eaccess eaccess
399 #ifdef ENCAPSULATE_LSTAT
400 int sys_lstat(const char *path, struct stat *buf);
402 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
404 # define lstat sys_lstat
406 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
407 # define sys_lstat lstat
410 #ifdef ENCAPSULATE_READLINK
411 int sys_readlink(const char *path, char *buf, size_t bufsiz);
413 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
415 # define readlink sys_readlink
417 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
418 # define sys_readlink readlink
421 #ifdef ENCAPSULATE_FSTAT
422 int sys_fstat(int fd, struct stat *buf);
424 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
426 # define fstat sys_fstat
428 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
429 # define sys_fstat fstat
432 int sxemacs_stat(const char *path, struct stat *buf);
434 /* encapsulations: file-manipulation calls */
436 #ifdef ENCAPSULATE_CHMOD
437 int sys_chmod(const char *path, mode_t mode);
439 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
441 # define chmod sys_chmod
443 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
444 # define sys_chmod chmod
447 #ifdef ENCAPSULATE_CREAT
448 int sys_creat(const char *path, mode_t mode);
450 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
452 # define creat sys_creat
454 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
455 # define sys_creat creat
458 #ifdef ENCAPSULATE_LINK
459 int sys_link(const char *existing, const char *new);
461 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
463 # define link sys_link
465 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
466 # define sys_link link
469 #ifdef ENCAPSULATE_RENAME
470 int sys_rename(const char *old, const char *new);
472 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
474 # define rename sys_rename
476 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
477 # define sys_rename rename
480 #ifdef ENCAPSULATE_SYMLINK
481 int sys_symlink(const char *name1, const char *name2);
483 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
485 # define symlink sys_symlink
487 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
488 # define sys_symlink symlink
491 #ifdef ENCAPSULATE_UNLINK
492 int sys_unlink(const char *path);
494 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
496 # define unlink sys_unlink
498 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
499 # define sys_unlink unlink
502 #ifdef ENCAPSULATE_EXECVP
503 int sys_execvp(const char *, char *const *);
505 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
507 # define execvp sys_execvp
509 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
510 # define sys_execvp execvp
513 /* How long can a source filename be in DOC (including "\037S" at the start
514 and "\n" at the end) ? */
515 #define DOC_MAX_FILENAME_LENGTH 2048
517 #endif /* INCLUDED_sysfile_h_ */