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