XEmacs 21.4.4 "Artificial Intelligence".
[chise/xemacs-chise.git.1] / src / sysfile.h
1 /*
2    Copyright (C) 1995 Free Software Foundation, Inc.
3
4 This file is part of XEmacs.
5
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
9 later version.
10
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
14 for more details.
15
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.  */
20
21 /* Synched up with: Not really in FSF. */
22
23 #ifndef INCLUDED_sysfile_h_
24 #define INCLUDED_sysfile_h_
25
26 #include <errno.h>
27
28 #ifndef WIN32_NATIVE
29 #include <sys/errno.h>          /* <errno.h> does not always imply this */
30 #endif
31
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35
36 #ifndef INCLUDED_FCNTL
37 # define INCLUDED_FCNTL
38 # include <fcntl.h>
39 #endif /* INCLUDED_FCNTL */
40
41 /* Load sys/types.h if not already loaded.
42    In some systems loading it twice is suicidal.  */
43 #ifndef makedev
44 #include <sys/types.h>          /* some typedefs are used in sys/file.h */
45 #endif
46
47 #ifndef WIN32_NATIVE
48 #include <sys/file.h>
49 #endif
50
51 #include <sys/stat.h>
52
53 #ifndef WIN32_NATIVE
54 /* Some configuration files' definitions for the LOAD_AVE_CVT macro
55    (like sparc.h's) use macros like FSCALE, defined here. */
56 #ifdef HAVE_GTK
57 /* I hate GTK */
58 #undef MIN
59 #undef MAX
60 #endif /* HAVE_GTK */
61 #include <sys/param.h>
62 #endif
63
64 #if defined (NeXT) || defined(CYGWIN)
65 /* what is needed from here?  Do others need it too?
66  O_BINARY is in here under cygwin. */
67 # include <sys/fcntl.h>
68 #endif /* NeXT */
69
70 #ifdef WIN32_NATIVE
71 #include <io.h>
72 #include <direct.h>
73 #endif
74
75 #ifndef STDERR_FILENO
76 #define STDIN_FILENO    0
77 #define STDOUT_FILENO   1
78 #define STDERR_FILENO   2
79 #endif
80
81 #ifndef O_RDONLY
82 #define O_RDONLY 0
83 #endif
84
85 #ifndef O_WRONLY
86 #define O_WRONLY 1
87 #endif
88
89 #ifndef O_RDWR
90 #define O_RDWR 2
91 #endif
92
93 /* file opening defaults */
94 #ifndef OPEN_BINARY
95 #ifdef O_BINARY
96 #define OPEN_BINARY     O_BINARY
97 #else
98 #define OPEN_BINARY     (0)
99 #endif
100 #endif
101
102 #ifndef OPEN_TEXT
103 #ifdef O_TEXT
104 #define OPEN_TEXT       O_TEXT
105 #else
106 #define OPEN_TEXT       (0)
107 #endif
108 #endif
109
110 #ifndef CREAT_MODE
111 #ifdef WIN32_NATIVE
112 #define CREAT_MODE      (S_IREAD | S_IWRITE)
113 #else
114 #define CREAT_MODE      (0666)
115 #endif
116 #endif
117
118 #ifndef READ_TEXT
119 #ifdef O_TEXT
120 #define READ_TEXT "rt"
121 #else
122 #define READ_TEXT "r"
123 #endif
124 #endif
125
126 #ifndef READ_BINARY
127 #ifdef O_BINARY
128 #define READ_BINARY "rb"
129 #else
130 #define READ_BINARY "r"
131 #endif
132 #endif
133
134 #ifndef READ_PLUS_TEXT
135 #ifdef O_TEXT
136 #define READ_PLUS_TEXT "r+t"
137 #else
138 #define READ_PLUS_TEXT "r+"
139 #endif
140 #endif
141
142 #ifndef READ_PLUS_BINARY
143 #ifdef O_BINARY
144 #define READ_PLUS_BINARY "r+b"
145 #else
146 #define READ_PLUS_BINARY "r+"
147 #endif
148 #endif
149
150 #ifndef WRITE_TEXT
151 #ifdef O_TEXT
152 #define WRITE_TEXT "wt"
153 #else
154 #define WRITE_TEXT "w"
155 #endif
156 #endif
157
158 #ifndef WRITE_BINARY
159 #ifdef O_BINARY
160 #define WRITE_BINARY "wb"
161 #else
162 #define WRITE_BINARY "w"
163 #endif
164 #endif
165
166 #ifndef O_NONBLOCK
167 #ifdef O_NDELAY
168 #define O_NONBLOCK O_NDELAY
169 #else
170 #define O_NONBLOCK 04000
171 #endif
172 #endif
173
174 /* if system does not have symbolic links, it does not have lstat.
175    In that case, use ordinary stat instead.  */
176
177 #ifndef S_IFLNK
178 #define lstat xemacs_stat
179 #endif
180
181 #ifndef S_IRUSR
182 # if S_IREAD
183 #  define S_IRUSR S_IREAD
184 # else
185 #  define S_IRUSR 00400
186 # endif
187 #endif
188
189 #ifndef S_IWUSR
190 # if S_IWRITE
191 #  define S_IWUSR S_IWRITE
192 # else
193 #  define S_IWUSR 00200
194 # endif
195 #endif
196
197 #ifndef S_IXUSR
198 # if S_IEXEC
199 #  define S_IXUSR S_IEXEC
200 # else
201 #  define S_IXUSR 00100
202 # endif
203 #endif
204
205 #ifdef STAT_MACROS_BROKEN
206 #undef S_ISBLK
207 #undef S_ISCHR
208 #undef S_ISDIR
209 #undef S_ISFIFO
210 #undef S_ISLNK
211 #undef S_ISMPB
212 #undef S_ISMPC
213 #undef S_ISNWK
214 #undef S_ISREG
215 #undef S_ISSOCK
216 #endif /* STAT_MACROS_BROKEN.  */
217
218 #if !defined(S_ISBLK) && defined(S_IFBLK)
219 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
220 #endif
221 #if !defined(S_ISCHR) && defined(S_IFCHR)
222 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
223 #endif
224 #if !defined(S_ISDIR) && defined(S_IFDIR)
225 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
226 #endif
227 #if !defined(S_ISREG) && defined(S_IFREG)
228 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
229 #endif
230 #if !defined(S_ISFIFO) && defined(S_IFIFO)
231 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
232 #endif
233 #if !defined(S_ISLNK) && defined(S_IFLNK)
234 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
235 #endif
236 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
237 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
238 #endif
239 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
240 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
241 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
242 #endif
243 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
244 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
245 #endif
246
247 /* Client .c files should simply use `PATH_MAX'. */
248 #ifndef PATH_MAX
249 # if defined (_POSIX_PATH_MAX)
250 #  define PATH_MAX _POSIX_PATH_MAX
251 # elif defined (MAXPATHLEN)
252 #  define PATH_MAX MAXPATHLEN
253 # else
254 #  define PATH_MAX 1024
255 # endif
256 #endif
257
258 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */
259 #ifndef MAXPATHLEN
260 # define MAXPATHLEN 1024
261 #endif
262
263 /* The following definitions are needed under Windows, at least */
264 #ifndef X_OK
265 # define X_OK 1
266 #endif
267
268 #ifndef R_OK
269 # define R_OK 4
270 #endif
271
272 #ifndef W_OK
273 # define W_OK 2
274 #endif
275
276 #ifndef F_OK
277 # define F_OK 0
278 #endif
279
280 #ifndef FD_CLOEXEC
281 # define FD_CLOEXEC 1
282 #endif
283
284 /* Emacs needs to use its own definitions of certain system calls on
285    some systems (like SunOS 4.1 and USG systems, where the read system
286    call is interruptible but Emacs expects it not to be; and under
287    MULE, where all filenames need to be converted to external format).
288    To do this, we #define read to be sys_read, which is defined in
289    sysdep.c.  We first #undef read, in case some system file defines
290    read as a macro.  sysdep.c doesn't encapsulate read, so the call to
291    read inside of sys_read will do the right thing.
292
293    DONT_ENCAPSULATE is used in files such as sysdep.c that want to
294    call the actual system calls rather than the encapsulated versions.
295    Those files can call sys_read to get the (possibly) encapsulated
296    versions.
297
298    IMPORTANT: the redefinition of the system call must occur *after* the
299    inclusion of any header files that declare or define the system call;
300    otherwise lots of unfriendly things can happen.  This goes for all
301    encapsulated system calls.
302
303    We encapsulate the most common system calls here; we assume their
304    declarations are in one of the standard header files included above.
305    Other encapsulations are declared in the appropriate sys*.h file. */
306
307 #ifdef ENCAPSULATE_READ
308 ssize_t sys_read (int, void *, size_t);
309 #endif
310 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
311 # undef read
312 # define read sys_read
313 #endif
314 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
315 # define sys_read read
316 #endif
317
318 #ifdef ENCAPSULATE_WRITE
319 ssize_t sys_write (int, const void *, size_t);
320 #endif
321 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
322 # undef write
323 # define write sys_write
324 #endif
325 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
326 # define sys_write write
327 #endif
328
329 #ifdef ENCAPSULATE_OPEN
330 int sys_open (const char *, int, ...);
331 #endif
332 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
333 # undef open
334 # define open sys_open
335 #endif
336 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
337 # define sys_open open
338 #endif
339
340 #ifdef ENCAPSULATE_CLOSE
341 int sys_close (int);
342 #endif
343 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
344 # undef close
345 # define close sys_close
346 #endif
347 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
348 # define sys_close close
349 #endif
350
351 /* Now the stdio versions ... */
352
353 #ifdef ENCAPSULATE_FREAD
354 size_t sys_fread (void *, size_t, size_t, FILE *);
355 #endif
356 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
357 # undef fread
358 # define fread sys_fread
359 #endif
360 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
361 # define sys_fread fread
362 #endif
363
364 #ifdef ENCAPSULATE_FWRITE
365 size_t sys_fwrite (const void *, size_t, size_t, FILE *);
366 #endif
367 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
368 # undef fwrite
369 # define fwrite sys_fwrite
370 #endif
371 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
372 # define sys_fwrite fwrite
373 #endif
374
375 #ifdef ENCAPSULATE_FOPEN
376 FILE *sys_fopen (const char *, const char *);
377 #endif
378 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
379 # undef fopen
380 # define fopen sys_fopen
381 #endif
382 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
383 # define sys_fopen fopen
384 #endif
385
386 #ifdef ENCAPSULATE_FCLOSE
387 int sys_fclose (FILE *);
388 #endif
389 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
390 # undef fclose
391 # define fclose sys_fclose
392 #endif
393 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
394 # define sys_fclose fclose
395 #endif
396
397
398 /* encapsulations: file-information calls */
399
400 #ifdef ENCAPSULATE_ACCESS
401 int sys_access (const char *path, int mode);
402 #endif
403 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
404 # undef access
405 # define access sys_access
406 #endif
407 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
408 # define sys_access access
409 #endif
410
411 #ifdef ENCAPSULATE_EACCESS
412 int sys_eaccess (const char *path, int mode);
413 #endif
414 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
415 # undef eaccess
416 # define eaccess sys_eaccess
417 #endif
418 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
419 # define sys_eaccess eaccess
420 #endif
421
422 #ifdef ENCAPSULATE_LSTAT
423 int sys_lstat (const char *path, struct stat *buf);
424 #endif
425 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
426 # undef lstat
427 # define lstat sys_lstat
428 #endif
429 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
430 # define sys_lstat lstat
431 #endif
432
433 #ifdef ENCAPSULATE_READLINK
434 int sys_readlink (const char *path, char *buf, size_t bufsiz);
435 #endif
436 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
437 # undef readlink
438 # define readlink sys_readlink
439 #endif
440 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
441 # define sys_readlink readlink
442 #endif
443
444 #ifdef ENCAPSULATE_FSTAT
445 int sys_fstat (int fd, struct stat *buf);
446 #endif
447 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE)
448 # undef fstat
449 # define fstat sys_fstat
450 #endif
451 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE)
452 # define sys_fstat fstat
453 #endif
454
455 int xemacs_stat (const char *path, struct stat *buf);
456
457 /* encapsulations: file-manipulation calls */
458
459 #ifdef ENCAPSULATE_CHMOD
460 int sys_chmod (const char *path, mode_t mode);
461 #endif
462 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
463 # undef chmod
464 # define chmod sys_chmod
465 #endif
466 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
467 # define sys_chmod chmod
468 #endif
469
470 #ifdef ENCAPSULATE_CREAT
471 int sys_creat (const char *path, mode_t mode);
472 #endif
473 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
474 # undef creat
475 # define creat sys_creat
476 #endif
477 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
478 # define sys_creat creat
479 #endif
480
481 #ifdef ENCAPSULATE_LINK
482 int sys_link (const char *existing, const char *new);
483 #endif
484 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
485 # undef link
486 # define link sys_link
487 #endif
488 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
489 # define sys_link link
490 #endif
491
492 #ifdef ENCAPSULATE_RENAME
493 int sys_rename (const char *old, const char *new);
494 #endif
495 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
496 # undef rename
497 # define rename sys_rename
498 #endif
499 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
500 # define sys_rename rename
501 #endif
502
503 #ifdef ENCAPSULATE_SYMLINK
504 int sys_symlink (const char *name1, const char *name2);
505 #endif
506 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
507 # undef symlink
508 # define symlink sys_symlink
509 #endif
510 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
511 # define sys_symlink symlink
512 #endif
513
514 #ifdef ENCAPSULATE_UNLINK
515 int sys_unlink (const char *path);
516 #endif
517 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
518 # undef unlink
519 # define unlink sys_unlink
520 #endif
521 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
522 # define sys_unlink unlink
523 #endif
524
525 #ifdef ENCAPSULATE_EXECVP
526 int sys_execvp (const char *, char * const *);
527 #endif
528 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
529 # undef execvp
530 # define execvp sys_execvp
531 #endif
532 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE)
533 # define sys_execvp execvp
534 #endif
535
536 #endif /* INCLUDED_sysfile_h_ */