Mercurial > hg > xemacs-beta
comparison src/sysfile.h @ 771:943eaba38521
[xemacs-hg @ 2002-03-13 08:51:24 by ben]
The big ben-mule-21-5 check-in!
Various files were added and deleted. See CHANGES-ben-mule.
There are still some test suite failures. No crashes, though.
Many of the failures have to do with problems in the test suite itself
rather than in the actual code. I'll be addressing these in the next
day or so -- none of the test suite failures are at all critical.
Meanwhile I'll be trying to address the biggest issues -- i.e. build
or run failures, which will almost certainly happen on various platforms.
All comments should be sent to ben@xemacs.org -- use a Cc: if necessary
when sending to mailing lists. There will be pre- and post- tags,
something like
pre-ben-mule-21-5-merge-in, and
post-ben-mule-21-5-merge-in.
author | ben |
---|---|
date | Wed, 13 Mar 2002 08:54:06 +0000 |
parents | 13e3d7ae7155 |
children | e65d9cf16707 |
comparison
equal
deleted
inserted
replaced
770:336a418893b5 | 771:943eaba38521 |
---|---|
1 /* | 1 /* |
2 Copyright (C) 1995 Free Software Foundation, Inc. | 2 Copyright (C) 1995 Free Software Foundation, Inc. |
3 Copyright (C) 2001 Ben Wing. | 3 Copyright (C) 2000, 2001 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
21 | 21 |
22 /* Synched up with: Not really in FSF. */ | 22 /* Synched up with: Not really in FSF. */ |
23 | 23 |
24 #ifndef INCLUDED_sysfile_h_ | 24 #ifndef INCLUDED_sysfile_h_ |
25 #define INCLUDED_sysfile_h_ | 25 #define INCLUDED_sysfile_h_ |
26 | |
27 /* The anonymous voice of the past says: | |
28 Must come before sysfile.h | |
29 | |
30 So instead we just put it here. --ben */ | |
31 #ifdef HAVE_LIBGEN_H | |
32 #include <libgen.h> | |
33 #endif | |
26 | 34 |
27 #include <errno.h> | 35 #include <errno.h> |
28 | 36 |
29 #ifndef WIN32_NATIVE | 37 #ifndef WIN32_NATIVE |
30 # include <sys/errno.h> /* <errno.h> does not always imply this */ | 38 # include <sys/errno.h> /* <errno.h> does not always imply this */ |
164 #else | 172 #else |
165 #define WRITE_BINARY "w" | 173 #define WRITE_BINARY "w" |
166 #endif | 174 #endif |
167 #endif | 175 #endif |
168 | 176 |
177 #ifndef APPEND_TEXT | |
178 #ifdef O_TEXT | |
179 #define APPEND_TEXT "at" | |
180 #else | |
181 #define APPEND_TEXT "a" | |
182 #endif | |
183 #endif | |
184 | |
185 #ifndef APPEND_BINARY | |
186 #ifdef O_BINARY | |
187 #define APPEND_BINARY "ab" | |
188 #else | |
189 #define APPEND_BINARY "a" | |
190 #endif | |
191 #endif | |
192 | |
169 #ifndef O_NONBLOCK | 193 #ifndef O_NONBLOCK |
170 #ifdef O_NDELAY | 194 #ifdef O_NDELAY |
171 #define O_NONBLOCK O_NDELAY | 195 #define O_NONBLOCK O_NDELAY |
172 #else | 196 #else |
173 #define O_NONBLOCK 04000 | 197 #define O_NONBLOCK 04000 |
174 #endif | 198 #endif |
175 #endif | |
176 | |
177 /* if system does not have symbolic links, it does not have lstat. | |
178 In that case, use ordinary stat instead. */ | |
179 | |
180 #ifndef S_IFLNK | |
181 #define lstat xemacs_stat | |
182 #endif | 199 #endif |
183 | 200 |
184 #if !S_IRUSR | 201 #if !S_IRUSR |
185 # if S_IREAD | 202 # if S_IREAD |
186 # define S_IRUSR S_IREAD | 203 # define S_IRUSR S_IREAD |
259 # else | 276 # else |
260 # define PATH_MAX 1024 | 277 # define PATH_MAX 1024 |
261 # endif | 278 # endif |
262 #endif | 279 #endif |
263 | 280 |
264 /* MAXPATHLEN is deprecated, but, as of this writing, still used. */ | |
265 #ifndef MAXPATHLEN | |
266 # define MAXPATHLEN 1024 | |
267 #endif | |
268 | |
269 /* The following definitions are needed under Windows, at least */ | 281 /* The following definitions are needed under Windows, at least */ |
270 #ifndef X_OK | 282 #ifndef X_OK |
271 # define X_OK 1 | 283 # define X_OK 1 |
272 #endif | 284 #endif |
273 | 285 |
274 #ifndef R_OK | 286 #ifndef R_OK |
275 # define R_OK 4 | 287 # define R_OK 4 |
276 #endif | 288 #endif |
277 | 289 |
290 #ifndef D_OK | |
291 # define D_OK 8 | |
292 #endif | |
293 | |
278 #ifndef W_OK | 294 #ifndef W_OK |
279 # define W_OK 2 | 295 # define W_OK 2 |
280 #endif | 296 #endif |
281 | 297 |
282 #ifndef F_OK | 298 #ifndef F_OK |
284 #endif | 300 #endif |
285 | 301 |
286 #ifndef FD_CLOEXEC | 302 #ifndef FD_CLOEXEC |
287 # define FD_CLOEXEC 1 | 303 # define FD_CLOEXEC 1 |
288 #endif | 304 #endif |
305 | |
306 #ifdef emacs | |
289 | 307 |
290 /* Emacs needs to use its own definitions of certain system calls on | 308 /* Emacs needs to use its own definitions of certain system calls on |
291 some systems (like SunOS 4.1 and USG systems, where the read system | 309 some systems (like SunOS 4.1 and USG systems, where the read system |
292 call is interruptible but Emacs expects it not to be; and under | 310 call is interruptible but Emacs expects it not to be; and under |
293 MULE, where all filenames need to be converted to external format). | 311 MULE, where all filenames need to be converted to external format). |
294 To do this, we #define read to be sys_read, which is defined in | 312 |
295 sysdep.c. We first #undef read, in case some system file defines | 313 We used to play preprocessor games, but in the long run that just leads |
296 read as a macro. sysdep.c doesn't encapsulate read, so the call to | 314 you to ruin. So we explicitly put in the new calls, even if the source |
297 read inside of sys_read will do the right thing. | 315 gets marginally less pretty. |
298 | 316 |
299 DONT_ENCAPSULATE is used in files such as sysdep.c that want to | 317 Current files where we don't use retry_ or qxe_ versions: |
300 call the actual system calls rather than the encapsulated versions. | 318 |
301 Those files can call sys_read to get the (possibly) encapsulated | 319 -- all sound files except ntplay.c (includes esd.c libsst.[ch] libst.h |
302 versions. | 320 linuxplay.c sgiplay.c sunplay.c |
303 | 321 hpplay.c nas.c) |
304 IMPORTANT: the redefinition of the system call must occur *after* the | 322 -- all unex* files |
305 inclusion of any header files that declare or define the system call; | 323 -- hftctl.c |
306 otherwise lots of unfriendly things can happen. This goes for all | 324 -- lib-src files |
307 encapsulated system calls. | 325 */ |
308 | 326 |
309 We encapsulate the most common system calls here; we assume their | 327 ssize_t retry_read (int, void *, size_t); |
310 declarations are in one of the standard header files included above. | 328 ssize_t retry_write (int, const void *, size_t); |
311 Other encapsulations are declared in the appropriate sys*.h file. */ | 329 int retry_open (const Extbyte *path, int oflag, ...); |
312 | 330 int qxe_open (const Intbyte *path, int oflag, ...); |
313 #ifdef ENCAPSULATE_READ | 331 int qxe_interruptible_open (const Intbyte *path, int oflag, int mode); |
314 ssize_t sys_read (int, void *, size_t); | 332 int retry_close (int); |
315 #endif | 333 Bytecount read_allowing_quit (int fildes, void *buf, Bytecount size); |
316 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE) | 334 Bytecount write_allowing_quit (int fildes, const void *buf, |
317 # undef read | 335 Bytecount size); |
318 # define read sys_read | |
319 #endif | |
320 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE) | |
321 # define sys_read read | |
322 #endif | |
323 | |
324 #ifdef ENCAPSULATE_WRITE | |
325 ssize_t sys_write (int, const void *, size_t); | |
326 #endif | |
327 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE) | |
328 # undef write | |
329 # define write sys_write | |
330 #endif | |
331 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE) | |
332 # define sys_write write | |
333 #endif | |
334 | |
335 #ifdef ENCAPSULATE_OPEN | |
336 int sys_open (const char *, int, ...); | |
337 #endif | |
338 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE) | |
339 # undef open | |
340 # define open sys_open | |
341 #endif | |
342 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE) | |
343 # define sys_open open | |
344 #endif | |
345 | |
346 #ifdef ENCAPSULATE_CLOSE | |
347 int sys_close (int); | |
348 #endif | |
349 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE) | |
350 # undef close | |
351 # define close sys_close | |
352 #endif | |
353 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE) | |
354 # define sys_close close | |
355 #endif | |
356 | 336 |
357 /* Now the stdio versions ... */ | 337 /* Now the stdio versions ... */ |
358 | 338 |
359 #ifdef ENCAPSULATE_FREAD | 339 size_t retry_fread (void *, size_t, size_t, FILE *); |
360 size_t sys_fread (void *, size_t, size_t, FILE *); | 340 size_t retry_fwrite (const void *, size_t, size_t, FILE *); |
361 #endif | 341 FILE *retry_fopen (const Extbyte *path, const Char_ASCII *mode); |
362 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE) | 342 FILE *qxe_fopen (const Intbyte *path, const Char_ASCII *mode); |
363 # undef fread | 343 int retry_fclose (FILE *); |
364 # define fread sys_fread | |
365 #endif | |
366 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE) | |
367 # define sys_fread fread | |
368 #endif | |
369 | |
370 #ifdef ENCAPSULATE_FWRITE | |
371 size_t sys_fwrite (const void *, size_t, size_t, FILE *); | |
372 #endif | |
373 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE) | |
374 # undef fwrite | |
375 # define fwrite sys_fwrite | |
376 #endif | |
377 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE) | |
378 # define sys_fwrite fwrite | |
379 #endif | |
380 | |
381 #ifdef ENCAPSULATE_FOPEN | |
382 FILE *sys_fopen (const char *, const char *); | |
383 #endif | |
384 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE) | |
385 # undef fopen | |
386 # define fopen sys_fopen | |
387 #endif | |
388 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE) | |
389 # define sys_fopen fopen | |
390 #endif | |
391 | |
392 #ifdef ENCAPSULATE_FCLOSE | |
393 int sys_fclose (FILE *); | |
394 #endif | |
395 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE) | |
396 # undef fclose | |
397 # define fclose sys_fclose | |
398 #endif | |
399 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE) | |
400 # define sys_fclose fclose | |
401 #endif | |
402 | |
403 | 344 |
404 /* encapsulations: file-information calls */ | 345 /* encapsulations: file-information calls */ |
405 | 346 |
406 #ifdef ENCAPSULATE_ACCESS | 347 int qxe_access (const Intbyte *path, int mode); |
407 int sys_access (const char *path, int mode); | 348 int qxe_eaccess (const Intbyte *path, int mode); |
408 #endif | 349 int qxe_lstat (const Intbyte *path, struct stat *buf); |
409 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE) | 350 int qxe_readlink (const Intbyte *path, Intbyte *buf, size_t bufsiz); |
410 # undef access | 351 int qxe_fstat (int fd, struct stat *buf); |
411 # define access sys_access | 352 int qxe_stat (const Intbyte *path, struct stat *buf); |
412 #endif | 353 Intbyte *qxe_realpath (const Intbyte *path, Intbyte resolved_path []); |
413 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE) | |
414 # define sys_access access | |
415 #endif | |
416 | |
417 #ifdef ENCAPSULATE_EACCESS | |
418 int sys_eaccess (const char *path, int mode); | |
419 #endif | |
420 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE) | |
421 # undef eaccess | |
422 # define eaccess sys_eaccess | |
423 #endif | |
424 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE) | |
425 # define sys_eaccess eaccess | |
426 #endif | |
427 | |
428 #ifdef ENCAPSULATE_LSTAT | |
429 int sys_lstat (const char *path, struct stat *buf); | |
430 #endif | |
431 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE) | |
432 # undef lstat | |
433 # define lstat sys_lstat | |
434 #endif | |
435 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE) | |
436 # define sys_lstat lstat | |
437 #endif | |
438 | |
439 #ifdef ENCAPSULATE_READLINK | |
440 int sys_readlink (const char *path, char *buf, size_t bufsiz); | |
441 #endif | |
442 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE) | |
443 # undef readlink | |
444 # define readlink sys_readlink | |
445 #endif | |
446 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE) | |
447 # define sys_readlink readlink | |
448 #endif | |
449 | |
450 #ifdef ENCAPSULATE_FSTAT | |
451 int sys_fstat (int fd, struct stat *buf); | |
452 #endif | |
453 #if defined (ENCAPSULATE_FSTAT) && !defined (DONT_ENCAPSULATE) | |
454 # undef fstat | |
455 # define fstat sys_fstat | |
456 #endif | |
457 #if !defined (ENCAPSULATE_FSTAT) && defined (DONT_ENCAPSULATE) | |
458 # define sys_fstat fstat | |
459 #endif | |
460 | |
461 int xemacs_stat (const char *path, struct stat *buf); | |
462 | 354 |
463 /* encapsulations: file-manipulation calls */ | 355 /* encapsulations: file-manipulation calls */ |
464 | 356 |
465 #ifdef ENCAPSULATE_CHMOD | 357 int qxe_chmod (const Intbyte *path, mode_t mode); |
466 int sys_chmod (const char *path, mode_t mode); | 358 |
467 #endif | 359 #if defined (HAVE_LINK) |
468 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE) | 360 int qxe_link (const Intbyte *existing, const Intbyte *new); |
469 # undef chmod | 361 #endif /* defined (HAVE_LINK) */ |
470 # define chmod sys_chmod | 362 |
471 #endif | 363 int qxe_rename (const Intbyte *old, const Intbyte *new); |
472 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE) | 364 |
473 # define sys_chmod chmod | 365 #if defined (HAVE_SYMLINK) |
474 #endif | 366 int qxe_symlink (const Intbyte *name1, const Intbyte *name2); |
475 | 367 #endif /* defined (HAVE_SYMLINK) */ |
476 #ifdef ENCAPSULATE_CREAT | 368 |
477 int sys_creat (const char *path, mode_t mode); | 369 int qxe_unlink (const Intbyte *path); |
478 #endif | 370 |
479 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE) | 371 #endif /* emacs */ |
480 # undef creat | 372 |
481 # define creat sys_creat | 373 |
482 #endif | 374 #ifndef HAVE_H_ERRNO |
483 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE) | 375 extern int h_errno; |
484 # define sys_creat creat | 376 #endif |
485 #endif | 377 |
486 | 378 #ifndef HAVE_DUP2 |
487 #ifdef ENCAPSULATE_LINK | 379 int dup2 (int oldd, int newd); |
488 int sys_link (const char *existing, const char *new); | 380 #endif |
489 #endif | 381 |
490 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE) | 382 #ifndef HAVE_STRERROR |
491 # undef link | 383 /* X11R6 defines strerror as a macro */ |
492 # define link sys_link | 384 # ifdef strerror |
493 #endif | 385 # undef strerror |
494 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE) | 386 # endif |
495 # define sys_link link | 387 const char *strerror (int); |
496 #endif | 388 #endif |
497 | 389 |
498 #ifdef ENCAPSULATE_RENAME | 390 |
499 int sys_rename (const char *old, const char *new); | 391 |
500 #endif | 392 /* |
501 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE) | 393 DEFAULT_DIRECTORY_SEP is the default value of Vdirectory_sep_char. |
502 # undef rename | 394 DIRECTORY_SEP is the currently preferred separator between elements |
503 # define rename sys_rename | 395 of a path, when paths are canonicalized. |
504 #endif | 396 DEVICE_SEP is the separator between devices and paths (might not |
505 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE) | 397 be defined). |
506 # define sys_rename rename | 398 SEPCHAR is the separator between paths in a path search string |
507 #endif | 399 (e.g. the PATH environment variable). |
508 | 400 IS_DIRECTORY_SEP() returns true if the character is any directory |
509 #ifdef ENCAPSULATE_SYMLINK | 401 separator (there might be more than one allowed on a system.). |
510 int sys_symlink (const char *name1, const char *name2); | 402 IS_DEVICE_SEP() returns true if the character is a device separator. |
511 #endif | 403 IS_ANY_SEP() returns true if the character is a directory or device |
512 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE) | 404 separator. |
513 # undef symlink | 405 */ |
514 # define symlink sys_symlink | 406 |
515 #endif | 407 #ifdef emacs |
516 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE) | 408 |
517 # define sys_symlink symlink | 409 /* We used to put some of this stuff in the s+m files for the various |
518 #endif | 410 types of MS Windows, but that's disingenuous. The various definitions |
519 | 411 above were specifically created for MS Windows, and the "if not, then |
520 #ifdef ENCAPSULATE_UNLINK | 412 let's define the defaults" stuff (formerly in lisp.h) specifically knows |
521 int sys_unlink (const char *path); | 413 about what is going to get redefined and how, and code all over the |
522 #endif | 414 place that works with filenames has to conditionalize on WIN32_NATIVE |
523 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE) | 415 anyway. It's much clearer if we put all related definitions in one |
524 # undef unlink | 416 place. (In fact, I discovered a number of bugs in the process.) |
525 # define unlink sys_unlink | 417 |
526 #endif | 418 S+M files should be used for simple on-off or multiple-choice settings, |
527 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE) | 419 or possibly string settings. Anything that gets to the level of |
528 # define sys_unlink unlink | 420 programming should be elsewhere, and anything that ends up having |
529 #endif | 421 lots of complicated interactions scattered around in many files should |
530 | 422 be consolidated. */ |
531 #ifdef ENCAPSULATE_EXECVP | 423 |
532 int sys_execvp (const char *, char * const *); | 424 #ifdef WIN32_NATIVE |
533 #endif | 425 |
534 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE) | 426 #define SEPCHAR ';' |
535 # undef execvp | 427 #define DEFAULT_DIRECTORY_SEP '\\' |
536 # define execvp sys_execvp | 428 |
537 #endif | 429 DECLARE_INLINE_HEADER (Intbyte sysfile_get_directory_sep (void)) |
538 #if !defined (ENCAPSULATE_EXECVP) && defined (DONT_ENCAPSULATE) | 430 { |
539 # define sys_execvp execvp | 431 if (!CHARP (Vdirectory_sep_char) |
540 #endif | 432 || (XCHAR (Vdirectory_sep_char) != '/' |
433 && XCHAR (Vdirectory_sep_char) != '\\')) | |
434 { | |
435 warn_when_safe | |
436 (Qfile_name, Qerror, | |
437 "`directory-sep-char' set to invalid %s: resetting to %c.", | |
438 DEFAULT_DIRECTORY_SEP); | |
439 Vdirectory_sep_char = make_char (DEFAULT_DIRECTORY_SEP); | |
440 } | |
441 | |
442 return XCHAR (Vdirectory_sep_char); | |
443 } | |
444 #define DIRECTORY_SEP sysfile_get_directory_sep() | |
445 | |
446 #else /* not WIN32_NATIVE */ | |
447 | |
448 #define SEPCHAR ':' | |
449 #define DEFAULT_DIRECTORY_SEP '/' | |
450 #define DIRECTORY_SEP '/' | |
451 | |
452 #endif /* WIN32_NATIVE */ | |
453 | |
454 | |
455 #if defined (WIN32_NATIVE) || defined (CYGWIN) | |
456 | |
457 #define DEVICE_SEP ':' | |
458 | |
459 #define IS_DEVICE_SEP(c) ((c) == DEVICE_SEP) | |
460 | |
461 DECLARE_INLINE_HEADER (int IS_DIRECTORY_SEP (Emchar c)) | |
462 { | |
463 return (c == '/' || c == '\\'); | |
464 } | |
465 | |
466 DECLARE_INLINE_HEADER (int IS_ANY_SEP (Emchar c)) | |
467 { | |
468 return (c == '/' || c == '\\' || c == ':'); | |
469 } | |
470 | |
471 #else /* not (defined (WIN32_NATIVE) || defined (CYGWIN)) */ | |
472 | |
473 #define IS_DEVICE_SEP(c) 0 | |
474 #define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP) | |
475 #define IS_ANY_SEP(c) IS_DIRECTORY_SEP (c) | |
476 | |
477 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN) */ | |
478 | |
479 #endif /* emacs */ | |
480 | |
541 | 481 |
542 #endif /* INCLUDED_sysfile_h_ */ | 482 #endif /* INCLUDED_sysfile_h_ */ |