428
+ − 1 /*
+ − 2 Copyright (C) 1995 Free Software Foundation, Inc.
777
+ − 3 Copyright (C) 2000, 2001, 2002 Ben Wing.
428
+ − 4
+ − 5 This file is part of XEmacs.
+ − 6
+ − 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
+ − 9 Free Software Foundation; either version 2, or (at your option) any
+ − 10 later version.
+ − 11
+ − 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 15 for more details.
+ − 16
+ − 17 You should have received a copy of the GNU General Public License
+ − 18 along with XEmacs; see the file COPYING. If not, write to
+ − 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 20 Boston, MA 02111-1307, USA. */
+ − 21
+ − 22 /* Synched up with: Not really in FSF. */
+ − 23
440
+ − 24 #ifndef INCLUDED_sysfile_h_
+ − 25 #define INCLUDED_sysfile_h_
+ − 26
771
+ − 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
+ − 34
428
+ − 35 #include <errno.h>
+ − 36
442
+ − 37 #ifndef WIN32_NATIVE
573
+ − 38 # include <sys/errno.h> /* <errno.h> does not always imply this */
428
+ − 39 #endif
+ − 40
+ − 41 #ifdef HAVE_UNISTD_H
558
+ − 42 # include <unistd.h>
428
+ − 43 #endif
+ − 44
+ − 45 #ifndef INCLUDED_FCNTL
+ − 46 # define INCLUDED_FCNTL
+ − 47 # include <fcntl.h>
+ − 48 #endif /* INCLUDED_FCNTL */
+ − 49
558
+ − 50 /* The anonymous voice of the past says:
428
+ − 51 In some systems loading it twice is suicidal. */
558
+ − 52 #ifndef INCLUDED_SYS_TYPES
+ − 53 # define INCLUDED_SYS_TYPES
+ − 54 # include <sys/types.h> /* some typedefs are used in sys/file.h */
+ − 55 #endif /* INCLUDED_SYS_TYPES */
442
+ − 56
+ − 57 #ifndef WIN32_NATIVE
558
+ − 58 # include <sys/file.h>
442
+ − 59 #endif
+ − 60
428
+ − 61 #include <sys/stat.h>
442
+ − 62
1315
+ − 63 #ifdef WIN32_ANY
558
+ − 64 # include <io.h>
+ − 65 #endif
+ − 66
+ − 67 #ifdef WIN32_NATIVE
+ − 68 # include <direct.h>
+ − 69 #else
442
+ − 70 /* Some configuration files' definitions for the LOAD_AVE_CVT macro
+ − 71 (like sparc.h's) use macros like FSCALE, defined here. */
558
+ − 72 # ifdef HAVE_GTK
462
+ − 73 /* I hate GTK */
558
+ − 74 # undef MIN
+ − 75 # undef MAX
+ − 76 # endif /* HAVE_GTK */
+ − 77 # include <sys/param.h>
609
+ − 78 /* As per Martin's recommendation, we do not include this. There was
+ − 79 a comment stating that stuff from here was needed on NeXT, Cygwin,
+ − 80 and sunplay.c. However, Cygwin includes this automatically from
+ − 81 fcntl.h, and Martin says that a "conforming" system should never
+ − 82 need this. We will put it back if necessary on systems requiring it. */
+ − 83 /* # include <sys/fcntl.h> */
777
+ − 84 #endif /* WIN32_NATIVE */
428
+ − 85
+ − 86 #ifndef STDERR_FILENO
+ − 87 #define STDIN_FILENO 0
+ − 88 #define STDOUT_FILENO 1
+ − 89 #define STDERR_FILENO 2
+ − 90 #endif
+ − 91
+ − 92 #ifndef O_RDONLY
+ − 93 #define O_RDONLY 0
+ − 94 #endif
+ − 95
+ − 96 #ifndef O_WRONLY
+ − 97 #define O_WRONLY 1
+ − 98 #endif
+ − 99
+ − 100 #ifndef O_RDWR
+ − 101 #define O_RDWR 2
+ − 102 #endif
+ − 103
+ − 104 /* file opening defaults */
+ − 105 #ifndef OPEN_BINARY
+ − 106 #ifdef O_BINARY
+ − 107 #define OPEN_BINARY O_BINARY
+ − 108 #else
+ − 109 #define OPEN_BINARY (0)
+ − 110 #endif
+ − 111 #endif
+ − 112
+ − 113 #ifndef OPEN_TEXT
+ − 114 #ifdef O_TEXT
+ − 115 #define OPEN_TEXT O_TEXT
+ − 116 #else
+ − 117 #define OPEN_TEXT (0)
+ − 118 #endif
+ − 119 #endif
+ − 120
+ − 121 #ifndef CREAT_MODE
442
+ − 122 #ifdef WIN32_NATIVE
428
+ − 123 #define CREAT_MODE (S_IREAD | S_IWRITE)
+ − 124 #else
+ − 125 #define CREAT_MODE (0666)
+ − 126 #endif
+ − 127 #endif
+ − 128
+ − 129 #ifndef READ_TEXT
+ − 130 #ifdef O_TEXT
+ − 131 #define READ_TEXT "rt"
+ − 132 #else
+ − 133 #define READ_TEXT "r"
+ − 134 #endif
+ − 135 #endif
+ − 136
+ − 137 #ifndef READ_BINARY
+ − 138 #ifdef O_BINARY
+ − 139 #define READ_BINARY "rb"
+ − 140 #else
+ − 141 #define READ_BINARY "r"
+ − 142 #endif
+ − 143 #endif
+ − 144
442
+ − 145 #ifndef READ_PLUS_TEXT
+ − 146 #ifdef O_TEXT
+ − 147 #define READ_PLUS_TEXT "r+t"
+ − 148 #else
+ − 149 #define READ_PLUS_TEXT "r+"
+ − 150 #endif
+ − 151 #endif
+ − 152
+ − 153 #ifndef READ_PLUS_BINARY
+ − 154 #ifdef O_BINARY
+ − 155 #define READ_PLUS_BINARY "r+b"
+ − 156 #else
+ − 157 #define READ_PLUS_BINARY "r+"
+ − 158 #endif
+ − 159 #endif
+ − 160
+ − 161 #ifndef WRITE_TEXT
+ − 162 #ifdef O_TEXT
+ − 163 #define WRITE_TEXT "wt"
+ − 164 #else
+ − 165 #define WRITE_TEXT "w"
+ − 166 #endif
+ − 167 #endif
+ − 168
428
+ − 169 #ifndef WRITE_BINARY
+ − 170 #ifdef O_BINARY
+ − 171 #define WRITE_BINARY "wb"
+ − 172 #else
+ − 173 #define WRITE_BINARY "w"
+ − 174 #endif
+ − 175 #endif
+ − 176
771
+ − 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
428
+ − 193 #ifndef O_NONBLOCK
+ − 194 #ifdef O_NDELAY
+ − 195 #define O_NONBLOCK O_NDELAY
+ − 196 #else
+ − 197 #define O_NONBLOCK 04000
+ − 198 #endif
+ − 199 #endif
+ − 200
+ − 201 #if !S_IRUSR
+ − 202 # if S_IREAD
+ − 203 # define S_IRUSR S_IREAD
+ − 204 # else
+ − 205 # define S_IRUSR 00400
+ − 206 # endif
+ − 207 #endif
+ − 208
+ − 209 #if !S_IWUSR
+ − 210 # if S_IWRITE
+ − 211 # define S_IWUSR S_IWRITE
+ − 212 # else
+ − 213 # define S_IWUSR 00200
+ − 214 # endif
+ − 215 #endif
+ − 216
+ − 217 #if !S_IXUSR
+ − 218 # if S_IEXEC
+ − 219 # define S_IXUSR S_IEXEC
+ − 220 # else
+ − 221 # define S_IXUSR 00100
+ − 222 # endif
+ − 223 #endif
+ − 224
+ − 225 #ifdef STAT_MACROS_BROKEN
+ − 226 #undef S_ISBLK
+ − 227 #undef S_ISCHR
+ − 228 #undef S_ISDIR
+ − 229 #undef S_ISFIFO
+ − 230 #undef S_ISLNK
+ − 231 #undef S_ISMPB
+ − 232 #undef S_ISMPC
+ − 233 #undef S_ISNWK
+ − 234 #undef S_ISREG
+ − 235 #undef S_ISSOCK
+ − 236 #endif /* STAT_MACROS_BROKEN. */
+ − 237
+ − 238 #if !defined(S_ISBLK) && defined(S_IFBLK)
+ − 239 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+ − 240 #endif
+ − 241 #if !defined(S_ISCHR) && defined(S_IFCHR)
+ − 242 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+ − 243 #endif
+ − 244 #if !defined(S_ISDIR) && defined(S_IFDIR)
+ − 245 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+ − 246 #endif
+ − 247 #if !defined(S_ISREG) && defined(S_IFREG)
+ − 248 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+ − 249 #endif
+ − 250 #if !defined(S_ISFIFO) && defined(S_IFIFO)
+ − 251 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+ − 252 #endif
+ − 253 #if !defined(S_ISLNK) && defined(S_IFLNK)
+ − 254 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+ − 255 #endif
+ − 256 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
+ − 257 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+ − 258 #endif
+ − 259 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
+ − 260 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
+ − 261 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
+ − 262 #endif
+ − 263 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
+ − 264 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
+ − 265 #endif
+ − 266
442
+ − 267 /* Client .c files should simply use `PATH_MAX'. */
+ − 268 #ifndef PATH_MAX
558
+ − 269 # if defined (_MAX_PATH)
+ − 270 /* MS Win -- and preferable to _POSIX_PATH_MAX, which is also defined */
+ − 271 # define PATH_MAX _MAX_PATH
+ − 272 # elif defined (_POSIX_PATH_MAX)
442
+ − 273 # define PATH_MAX _POSIX_PATH_MAX
+ − 274 # elif defined (MAXPATHLEN)
+ − 275 # define PATH_MAX MAXPATHLEN
+ − 276 # else
+ − 277 # define PATH_MAX 1024
+ − 278 # endif
+ − 279 #endif
+ − 280
+ − 281 /* The following definitions are needed under Windows, at least */
+ − 282 #ifndef X_OK
+ − 283 # define X_OK 1
+ − 284 #endif
428
+ − 285
442
+ − 286 #ifndef R_OK
+ − 287 # define R_OK 4
+ − 288 #endif
+ − 289
771
+ − 290 #ifndef D_OK
+ − 291 # define D_OK 8
+ − 292 #endif
+ − 293
442
+ − 294 #ifndef W_OK
+ − 295 # define W_OK 2
+ − 296 #endif
+ − 297
+ − 298 #ifndef F_OK
+ − 299 # define F_OK 0
428
+ − 300 #endif
+ − 301
+ − 302 #ifndef FD_CLOEXEC
+ − 303 # define FD_CLOEXEC 1
+ − 304 #endif
+ − 305
771
+ − 306 #ifdef emacs
+ − 307
428
+ − 308 /* Emacs needs to use its own definitions of certain system calls on
+ − 309 some systems (like SunOS 4.1 and USG systems, where the read system
+ − 310 call is interruptible but Emacs expects it not to be; and under
+ − 311 MULE, where all filenames need to be converted to external format).
+ − 312
771
+ − 313 We used to play preprocessor games, but in the long run that just leads
+ − 314 you to ruin. So we explicitly put in the new calls, even if the source
+ − 315 gets marginally less pretty.
428
+ − 316
771
+ − 317 Current files where we don't use retry_ or qxe_ versions:
428
+ − 318
771
+ − 319 -- all sound files except ntplay.c (includes esd.c libsst.[ch] libst.h
+ − 320 linuxplay.c sgiplay.c sunplay.c
+ − 321 hpplay.c nas.c)
+ − 322 -- all unex* files
+ − 323 -- hftctl.c
+ − 324 -- lib-src files
+ − 325 */
428
+ − 326
771
+ − 327 ssize_t retry_read (int, void *, size_t);
+ − 328 ssize_t retry_write (int, const void *, size_t);
+ − 329 int retry_open (const Extbyte *path, int oflag, ...);
867
+ − 330 int qxe_open (const Ibyte *path, int oflag, ...);
+ − 331 int qxe_interruptible_open (const Ibyte *path, int oflag, int mode);
771
+ − 332 int retry_close (int);
+ − 333 Bytecount read_allowing_quit (int fildes, void *buf, Bytecount size);
+ − 334 Bytecount write_allowing_quit (int fildes, const void *buf,
+ − 335 Bytecount size);
428
+ − 336
+ − 337 /* Now the stdio versions ... */
+ − 338
771
+ − 339 size_t retry_fread (void *, size_t, size_t, FILE *);
+ − 340 size_t retry_fwrite (const void *, size_t, size_t, FILE *);
+ − 341 FILE *retry_fopen (const Extbyte *path, const Char_ASCII *mode);
867
+ − 342 FILE *qxe_fopen (const Ibyte *path, const Char_ASCII *mode);
771
+ − 343 int retry_fclose (FILE *);
428
+ − 344
+ − 345 /* encapsulations: file-information calls */
+ − 346
867
+ − 347 int qxe_access (const Ibyte *path, int mode);
+ − 348 int qxe_eaccess (const Ibyte *path, int mode);
+ − 349 int qxe_lstat (const Ibyte *path, struct stat *buf);
+ − 350 int qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz);
771
+ − 351 int qxe_fstat (int fd, struct stat *buf);
867
+ − 352 int qxe_stat (const Ibyte *path, struct stat *buf);
+ − 353 Ibyte *qxe_realpath (const Ibyte *path, Ibyte resolved_path []);
428
+ − 354
+ − 355 /* encapsulations: file-manipulation calls */
+ − 356
867
+ − 357 int qxe_chmod (const Ibyte *path, mode_t mode);
771
+ − 358
+ − 359 #if defined (HAVE_LINK)
867
+ − 360 int qxe_link (const Ibyte *existing, const Ibyte *new);
771
+ − 361 #endif /* defined (HAVE_LINK) */
+ − 362
867
+ − 363 int qxe_rename (const Ibyte *old, const Ibyte *new);
771
+ − 364
+ − 365 #if defined (HAVE_SYMLINK)
867
+ − 366 int qxe_symlink (const Ibyte *name1, const Ibyte *name2);
771
+ − 367 #endif /* defined (HAVE_SYMLINK) */
+ − 368
867
+ − 369 int qxe_unlink (const Ibyte *path);
771
+ − 370
+ − 371 #endif /* emacs */
+ − 372
+ − 373
+ − 374 #ifndef HAVE_H_ERRNO
+ − 375 extern int h_errno;
428
+ − 376 #endif
+ − 377
771
+ − 378 #ifndef HAVE_DUP2
+ − 379 int dup2 (int oldd, int newd);
428
+ − 380 #endif
+ − 381
771
+ − 382 #ifndef HAVE_STRERROR
+ − 383 /* X11R6 defines strerror as a macro */
+ − 384 # ifdef strerror
+ − 385 # undef strerror
+ − 386 # endif
+ − 387 const char *strerror (int);
428
+ − 388 #endif
+ − 389
771
+ − 390
+ − 391
+ − 392 /*
+ − 393 DEFAULT_DIRECTORY_SEP is the default value of Vdirectory_sep_char.
+ − 394 DIRECTORY_SEP is the currently preferred separator between elements
+ − 395 of a path, when paths are canonicalized.
+ − 396 DEVICE_SEP is the separator between devices and paths (might not
+ − 397 be defined).
+ − 398 SEPCHAR is the separator between paths in a path search string
+ − 399 (e.g. the PATH environment variable).
+ − 400 IS_DIRECTORY_SEP() returns true if the character is any directory
+ − 401 separator (there might be more than one allowed on a system.).
+ − 402 IS_DEVICE_SEP() returns true if the character is a device separator.
+ − 403 IS_ANY_SEP() returns true if the character is a directory or device
+ − 404 separator.
+ − 405 */
+ − 406
+ − 407 #ifdef emacs
428
+ − 408
771
+ − 409 /* We used to put some of this stuff in the s+m files for the various
+ − 410 types of MS Windows, but that's disingenuous. The various definitions
+ − 411 above were specifically created for MS Windows, and the "if not, then
+ − 412 let's define the defaults" stuff (formerly in lisp.h) specifically knows
+ − 413 about what is going to get redefined and how, and code all over the
+ − 414 place that works with filenames has to conditionalize on WIN32_NATIVE
+ − 415 anyway. It's much clearer if we put all related definitions in one
+ − 416 place. (In fact, I discovered a number of bugs in the process.)
+ − 417
+ − 418 S+M files should be used for simple on-off or multiple-choice settings,
+ − 419 or possibly string settings. Anything that gets to the level of
+ − 420 programming should be elsewhere, and anything that ends up having
+ − 421 lots of complicated interactions scattered around in many files should
+ − 422 be consolidated. */
+ − 423
+ − 424 #ifdef WIN32_NATIVE
+ − 425
+ − 426 #define SEPCHAR ';'
+ − 427 #define DEFAULT_DIRECTORY_SEP '\\'
428
+ − 428
867
+ − 429 DECLARE_INLINE_HEADER (Ibyte sysfile_get_directory_sep (void))
771
+ − 430 {
+ − 431 if (!CHARP (Vdirectory_sep_char)
+ − 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
428
+ − 454
1315
+ − 455 #ifdef WIN32_ANY
771
+ − 456
+ − 457 #define DEVICE_SEP ':'
+ − 458
+ − 459 #define IS_DEVICE_SEP(c) ((c) == DEVICE_SEP)
+ − 460
867
+ − 461 DECLARE_INLINE_HEADER (int IS_DIRECTORY_SEP (Ichar c))
771
+ − 462 {
+ − 463 return (c == '/' || c == '\\');
+ − 464 }
+ − 465
867
+ − 466 DECLARE_INLINE_HEADER (int IS_ANY_SEP (Ichar c))
771
+ − 467 {
+ − 468 return (c == '/' || c == '\\' || c == ':');
+ − 469 }
+ − 470
1315
+ − 471 #else /* not WIN32_ANY */
771
+ − 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
1315
+ − 477 #endif /* WIN32_ANY */
771
+ − 478
+ − 479 #endif /* emacs */
+ − 480
440
+ − 481
+ − 482 #endif /* INCLUDED_sysfile_h_ */