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