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