comparison src/sysfile.h @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 677f6a0ee643
children e11d67e05968
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
24 24
25 #ifndef WINDOWSNT 25 #ifndef WINDOWSNT
26 #include <sys/errno.h> /* <errno.h> does not always imply this */ 26 #include <sys/errno.h> /* <errno.h> does not always imply this */
27 #endif 27 #endif
28 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
29 /* Load sys/types.h if not already loaded. 38 /* Load sys/types.h if not already loaded.
30 In some systems loading it twice is suicidal. */ 39 In some systems loading it twice is suicidal. */
31 #ifndef makedev 40 #ifndef makedev
32 #include <sys/types.h> /* some typedefs are used in sys/file.h */ 41 #include <sys/types.h> /* some typedefs are used in sys/file.h */
33 #endif 42 #endif
34 #include <sys/file.h> 43 #include <sys/file.h>
35 #include <sys/stat.h> 44 #include <sys/stat.h>
36 #include <sys/param.h> 45 #include <sys/param.h>
37 46
38 #if defined (NeXT) || defined(__CYGWIN32__) 47 #if defined (NeXT) || defined(__CYGWIN32__)
39 /* what is needed from here? Do others need it too? 48 /* what is needed from here? Do others need it too?
40 O_BINARY is in here under cygwin. */ 49 O_BINARY is in here under cygwin. */
41 # include <sys/fcntl.h> 50 # include <sys/fcntl.h>
42 #endif /* NeXT */ 51 #endif /* NeXT */
43 52
44 #ifdef WINDOWSNT 53 #ifdef WINDOWSNT
209 218
210 #ifndef FD_CLOEXEC 219 #ifndef FD_CLOEXEC
211 # define FD_CLOEXEC 1 220 # define FD_CLOEXEC 1
212 #endif 221 #endif
213 222
223 /* Emacs needs to use its own definitions of certain system calls on
224 some systems (like SunOS 4.1 and USG systems, where the read system
225 call is interruptible but Emacs expects it not to be; and under
226 MULE, where all filenames need to be converted to external format).
227 To do this, we #define read to be sys_read, which is defined in
228 sysdep.c. We first #undef read, in case some system file defines
229 read as a macro. sysdep.c doesn't encapsulate read, so the call to
230 read inside of sys_read will do the right thing.
231
232 DONT_ENCAPSULATE is used in files such as sysdep.c that want to
233 call the actual system calls rather than the encapsulated versions.
234 Those files can call sys_read to get the (possibly) encapsulated
235 versions.
236
237 IMPORTANT: the redefinition of the system call must occur *after* the
238 inclusion of any header files that declare or define the system call;
239 otherwise lots of unfriendly things can happen. This goes for all
240 encapsulated system calls.
241
242 We encapsulate the most common system calls here; we assume their
243 declarations are in one of the standard header files included above.
244 Other encapsulations are declared in the appropriate sys*.h file. */
245
246 #ifdef ENCAPSULATE_READ
247 int sys_read (int, void *, size_t);
248 #endif
249 #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
250 # undef read
251 # define read sys_read
252 #endif
253 #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
254 # define sys_read read
255 #endif
256
257 #ifdef ENCAPSULATE_WRITE
258 int sys_write (int, CONST void *, size_t);
259 #endif
260 #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
261 # undef write
262 # define write sys_write
263 #endif
264 #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
265 # define sys_write write
266 #endif
267
268 #ifdef ENCAPSULATE_OPEN
269 int sys_open (CONST char *, int, ...);
270 #endif
271 #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
272 # undef open
273 # define open sys_open
274 #endif
275 #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
276 # define sys_open open
277 #endif
278
279 #ifdef ENCAPSULATE_CLOSE
280 int sys_close (int);
281 #endif
282 #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
283 # undef close
284 # define close sys_close
285 #endif
286 #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
287 # define sys_close close
288 #endif
289
290 /* Now the stdio versions ... */
291
292 #ifdef ENCAPSULATE_FREAD
293 size_t sys_fread (void *, size_t, size_t, FILE *);
294 #endif
295 #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
296 # undef fread
297 # define fread sys_fread
298 #endif
299 #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
300 # define sys_fread fread
301 #endif
302
303 #ifdef ENCAPSULATE_FWRITE
304 size_t sys_fwrite (CONST void *, size_t, size_t, FILE *);
305 #endif
306 #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
307 # undef fwrite
308 # define fwrite sys_fwrite
309 #endif
310 #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
311 # define sys_fwrite fwrite
312 #endif
313
314 #ifdef ENCAPSULATE_FOPEN
315 FILE *sys_fopen (CONST char *, CONST char *);
316 #endif
317 #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
318 # undef fopen
319 # define fopen sys_fopen
320 #endif
321 #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
322 # define sys_fopen fopen
323 #endif
324
325 #ifdef ENCAPSULATE_FCLOSE
326 int sys_fclose (FILE *);
327 #endif
328 #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
329 # undef fclose
330 # define fclose sys_fclose
331 #endif
332 #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
333 # define sys_fclose fclose
334 #endif
335
336
214 /* encapsulations: file-information calls */ 337 /* encapsulations: file-information calls */
215 338
216 #ifdef ENCAPSULATE_ACCESS 339 #ifdef ENCAPSULATE_ACCESS
217 extern int sys_access (CONST char *path, int mode); 340 int sys_access (CONST char *path, int mode);
218 #endif 341 #endif
219 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE) 342 #if defined (ENCAPSULATE_ACCESS) && !defined (DONT_ENCAPSULATE)
220 # undef access 343 # undef access
221 # define access sys_access 344 # define access sys_access
222 #endif 345 #endif
223 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE) 346 #if !defined (ENCAPSULATE_ACCESS) && defined (DONT_ENCAPSULATE)
224 # define sys_access access 347 # define sys_access access
225 #endif 348 #endif
226 349
227 #ifdef ENCAPSULATE_EACCESS 350 #ifdef ENCAPSULATE_EACCESS
228 extern int sys_eaccess (CONST char *path, int mode); 351 int sys_eaccess (CONST char *path, int mode);
229 #endif 352 #endif
230 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE) 353 #if defined (ENCAPSULATE_EACCESS) && !defined (DONT_ENCAPSULATE)
231 # undef eaccess 354 # undef eaccess
232 # define eaccess sys_eaccess 355 # define eaccess sys_eaccess
233 #endif 356 #endif
234 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE) 357 #if !defined (ENCAPSULATE_EACCESS) && defined (DONT_ENCAPSULATE)
235 # define sys_eaccess eaccess 358 # define sys_eaccess eaccess
236 #endif 359 #endif
237 360
238 #ifdef ENCAPSULATE_LSTAT 361 #ifdef ENCAPSULATE_LSTAT
239 extern int sys_lstat (CONST char *path, struct stat *buf); 362 int sys_lstat (CONST char *path, struct stat *buf);
240 #endif 363 #endif
241 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE) 364 #if defined (ENCAPSULATE_LSTAT) && !defined (DONT_ENCAPSULATE)
242 # undef lstat 365 # undef lstat
243 # define lstat sys_lstat 366 # define lstat sys_lstat
244 #endif 367 #endif
245 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE) 368 #if !defined (ENCAPSULATE_LSTAT) && defined (DONT_ENCAPSULATE)
246 # define sys_lstat lstat 369 # define sys_lstat lstat
247 #endif 370 #endif
248 371
249 #ifdef ENCAPSULATE_READLINK 372 #ifdef ENCAPSULATE_READLINK
250 extern int sys_readlink (CONST char *path, char *buf, int bufsiz); 373 int sys_readlink (CONST char *path, char *buf, size_t bufsiz);
251 #endif 374 #endif
252 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE) 375 #if defined (ENCAPSULATE_READLINK) && !defined (DONT_ENCAPSULATE)
253 # undef readlink 376 # undef readlink
254 # define readlink sys_readlink 377 # define readlink sys_readlink
255 #endif 378 #endif
256 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE) 379 #if !defined (ENCAPSULATE_READLINK) && defined (DONT_ENCAPSULATE)
257 # define sys_readlink readlink 380 # define sys_readlink readlink
258 #endif 381 #endif
259 382
260 #ifdef ENCAPSULATE_STAT 383 #ifdef ENCAPSULATE_STAT
261 extern int sys_stat (CONST char *path, struct stat *buf); 384 int sys_stat (CONST char *path, struct stat *buf);
262 #endif 385 #endif
263 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE) 386 #if defined (ENCAPSULATE_STAT) && !defined (DONT_ENCAPSULATE)
264 # undef stat 387 # undef stat
265 /* Need to use arguments to avoid messing with struct stat */ 388 /* Need to use arguments to avoid messing with struct stat */
266 # define stat(path, buf) sys_stat (path, buf) 389 # define stat(path, buf) sys_stat (path, buf)
270 #endif 393 #endif
271 394
272 /* encapsulations: file-manipulation calls */ 395 /* encapsulations: file-manipulation calls */
273 396
274 #ifdef ENCAPSULATE_CHMOD 397 #ifdef ENCAPSULATE_CHMOD
275 extern int sys_chmod (CONST char *path, int mode); 398 int sys_chmod (CONST char *path, mode_t mode);
276 #endif 399 #endif
277 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE) 400 #if defined (ENCAPSULATE_CHMOD) && !defined (DONT_ENCAPSULATE)
278 # undef chmod 401 # undef chmod
279 # define chmod sys_chmod 402 # define chmod sys_chmod
280 #endif 403 #endif
281 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE) 404 #if !defined (ENCAPSULATE_CHMOD) && defined (DONT_ENCAPSULATE)
282 # define sys_chmod chmod 405 # define sys_chmod chmod
283 #endif 406 #endif
284 407
285 #ifdef ENCAPSULATE_CREAT 408 #ifdef ENCAPSULATE_CREAT
286 extern int sys_creat (CONST char *path, int mode); 409 int sys_creat (CONST char *path, mode_t mode);
287 #endif 410 #endif
288 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE) 411 #if defined (ENCAPSULATE_CREAT) && !defined (DONT_ENCAPSULATE)
289 # undef creat 412 # undef creat
290 # define creat sys_creat 413 # define creat sys_creat
291 #endif 414 #endif
292 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE) 415 #if !defined (ENCAPSULATE_CREAT) && defined (DONT_ENCAPSULATE)
293 # define sys_creat creat 416 # define sys_creat creat
294 #endif 417 #endif
295 418
296 #ifdef ENCAPSULATE_LINK 419 #ifdef ENCAPSULATE_LINK
297 extern int sys_link (CONST char *existing, CONST char *new); 420 int sys_link (CONST char *existing, CONST char *new);
298 #endif 421 #endif
299 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE) 422 #if defined (ENCAPSULATE_LINK) && !defined (DONT_ENCAPSULATE)
300 # undef link 423 # undef link
301 # define link sys_link 424 # define link sys_link
302 #endif 425 #endif
303 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE) 426 #if !defined (ENCAPSULATE_LINK) && defined (DONT_ENCAPSULATE)
304 # define sys_link link 427 # define sys_link link
305 #endif 428 #endif
306 429
307 #ifdef ENCAPSULATE_RENAME 430 #ifdef ENCAPSULATE_RENAME
308 extern int sys_rename (CONST char *old, CONST char *new); 431 int sys_rename (CONST char *old, CONST char *new);
309 #endif 432 #endif
310 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE) 433 #if defined (ENCAPSULATE_RENAME) && !defined (DONT_ENCAPSULATE)
311 # undef rename 434 # undef rename
312 # define rename sys_rename 435 # define rename sys_rename
313 #endif 436 #endif
314 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE) 437 #if !defined (ENCAPSULATE_RENAME) && defined (DONT_ENCAPSULATE)
315 # define sys_rename rename 438 # define sys_rename rename
316 #endif 439 #endif
317 440
318 #ifdef ENCAPSULATE_SYMLINK 441 #ifdef ENCAPSULATE_SYMLINK
319 extern int sys_symlink (CONST char *name1, CONST char *name2); 442 int sys_symlink (CONST char *name1, CONST char *name2);
320 #endif 443 #endif
321 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE) 444 #if defined (ENCAPSULATE_SYMLINK) && !defined (DONT_ENCAPSULATE)
322 # undef symlink 445 # undef symlink
323 # define symlink sys_symlink 446 # define symlink sys_symlink
324 #endif 447 #endif
325 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE) 448 #if !defined (ENCAPSULATE_SYMLINK) && defined (DONT_ENCAPSULATE)
326 # define sys_symlink symlink 449 # define sys_symlink symlink
327 #endif 450 #endif
328 451
329 #ifdef ENCAPSULATE_UNLINK 452 #ifdef ENCAPSULATE_UNLINK
330 extern int sys_unlink (CONST char *path); 453 int sys_unlink (CONST char *path);
331 #endif 454 #endif
332 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE) 455 #if defined (ENCAPSULATE_UNLINK) && !defined (DONT_ENCAPSULATE)
333 # undef unlink 456 # undef unlink
334 # define unlink sys_unlink 457 # define unlink sys_unlink
335 #endif 458 #endif
336 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE) 459 #if !defined (ENCAPSULATE_UNLINK) && defined (DONT_ENCAPSULATE)
337 # define sys_unlink unlink 460 # define sys_unlink unlink
338 #endif 461 #endif
339 462
340 #ifdef ENCAPSULATE_EXECVP 463 #ifdef ENCAPSULATE_EXECVP
341 extern int sys_execvp (CONST char *, char * CONST *); 464 int sys_execvp (CONST char *, char * CONST *);
342 #endif 465 #endif
343 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE) 466 #if defined (ENCAPSULATE_EXECVP) && !defined (DONT_ENCAPSULATE)
344 # undef execvp 467 # undef execvp
345 # define execvp sys_execvp 468 # define execvp sys_execvp
346 #endif 469 #endif