diff options
| author | Paul Eggert | 2013-07-05 19:40:50 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-07-05 19:40:50 -0700 |
| commit | 406af475be236b874e3633b68999f6a099d47587 (patch) | |
| tree | 4dfc0e61b3fce353adedc96f84091aca4ae23b57 /src | |
| parent | 0773c610689c7612b0d7b44e61701079b6f56419 (diff) | |
| download | emacs-406af475be236b874e3633b68999f6a099d47587.tar.gz emacs-406af475be236b874e3633b68999f6a099d47587.zip | |
Use emacs_open more consistently when opening files.
This handles EINTR more consistently now, and makes it easier
to introduce other uniform changes to file descriptor handling.
* src/systdio.h: New file.
* src/buffer.c (mmap_init):
* cygw32.c (chdir_to_default_directory):
* dispnew.c (Fopen_termscript):
* emacs.c (Fdaemon_initialized):
* fileio.c (Fdo_auto_save):
* image.c (slurp_file, png_load_body, jpeg_load_body):
* keyboard.c (Fopen_dribble_file):
* lread.c (Fload):
* print.c (Fredirect_debugging_output):
* sysdep.c (get_up_time, procfs_ttyname, procfs_get_total_memory):
* termcap.c (tgetent):
* unexaix.c, unexcoff.c (unexec, adjust_lnnoptrs):
* unexcw.c, unexelf.c, unexhp9k800.c, unexmacosx.c (unexec):
* w32term.c (w32_initialize) [CYGWIN]:
* xfaces.c (Fx_load_color_file):
Use emacs_open instead of plain open, and emacs_fopen instead of
plain fopen.
* dispnew.c, fileio.c, image.c, keyboard.c, lread.c, print.c, sysdep.c:
* xfaces.c: Include sysstdio.h rather than stdio.h, for emacs_fopen.
* callproc.c (default_output_mode): New constant.
(Fcall_process): Use it to call emacs_open instead of plain creat.
* dispnew.c (Fopen_termscript): Fix minor race in opening termscript.
* sysdep.c (emacs_open): Add commentary and don't call file name "path".
(emacs_fopen): New function.
* unexaix.c, unexcoff.c, unexelf.c, unexhp9k800.c, unexmacosx.c:
Include <lisp.h>, for emacs_open.
* unexelf.c (fatal): Remove decl; not needed with <lisp.h> included.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 32 | ||||
| -rw-r--r-- | src/buffer.c | 2 | ||||
| -rw-r--r-- | src/callproc.c | 29 | ||||
| -rw-r--r-- | src/cygw32.c | 2 | ||||
| -rw-r--r-- | src/dispnew.c | 16 | ||||
| -rw-r--r-- | src/emacs.c | 2 | ||||
| -rw-r--r-- | src/fileio.c | 4 | ||||
| -rw-r--r-- | src/image.c | 8 | ||||
| -rw-r--r-- | src/keyboard.c | 4 | ||||
| -rw-r--r-- | src/lread.c | 4 | ||||
| -rw-r--r-- | src/print.c | 4 | ||||
| -rw-r--r-- | src/sysdep.c | 32 | ||||
| -rw-r--r-- | src/sysstdio.h | 2 | ||||
| -rw-r--r-- | src/term.c | 2 | ||||
| -rw-r--r-- | src/termcap.c | 6 | ||||
| -rw-r--r-- | src/unexaix.c | 7 | ||||
| -rw-r--r-- | src/unexcoff.c | 7 | ||||
| -rw-r--r-- | src/unexcw.c | 6 | ||||
| -rw-r--r-- | src/unexelf.c | 11 | ||||
| -rw-r--r-- | src/unexhp9k800.c | 5 | ||||
| -rw-r--r-- | src/unexmacosx.c | 5 | ||||
| -rw-r--r-- | src/w32term.c | 2 | ||||
| -rw-r--r-- | src/xfaces.c | 4 |
23 files changed, 120 insertions, 76 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d42f5733ce6..0465bdcaf2e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,37 @@ | |||
| 1 | 2013-07-05 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-07-05 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Use emacs_open more consistently when opening files. | ||
| 4 | This handles EINTR more consistently now, and makes it easier | ||
| 5 | to introduce other uniform changes to file descriptor handling. | ||
| 6 | * src/systdio.h: New file. | ||
| 7 | * src/buffer.c (mmap_init): | ||
| 8 | * cygw32.c (chdir_to_default_directory): | ||
| 9 | * dispnew.c (Fopen_termscript): | ||
| 10 | * emacs.c (Fdaemon_initialized): | ||
| 11 | * fileio.c (Fdo_auto_save): | ||
| 12 | * image.c (slurp_file, png_load_body, jpeg_load_body): | ||
| 13 | * keyboard.c (Fopen_dribble_file): | ||
| 14 | * lread.c (Fload): | ||
| 15 | * print.c (Fredirect_debugging_output): | ||
| 16 | * sysdep.c (get_up_time, procfs_ttyname, procfs_get_total_memory): | ||
| 17 | * termcap.c (tgetent): | ||
| 18 | * unexaix.c, unexcoff.c (unexec, adjust_lnnoptrs): | ||
| 19 | * unexcw.c, unexelf.c, unexhp9k800.c, unexmacosx.c (unexec): | ||
| 20 | * w32term.c (w32_initialize) [CYGWIN]: | ||
| 21 | * xfaces.c (Fx_load_color_file): | ||
| 22 | Use emacs_open instead of plain open, and emacs_fopen instead of | ||
| 23 | plain fopen. | ||
| 24 | * dispnew.c, fileio.c, image.c, keyboard.c, lread.c, print.c, sysdep.c: | ||
| 25 | * xfaces.c: Include sysstdio.h rather than stdio.h, for emacs_fopen. | ||
| 26 | * callproc.c (default_output_mode): New constant. | ||
| 27 | (Fcall_process): Use it to call emacs_open instead of plain creat. | ||
| 28 | * dispnew.c (Fopen_termscript): Fix minor race in opening termscript. | ||
| 29 | * sysdep.c (emacs_open): Add commentary and don't call file name "path". | ||
| 30 | (emacs_fopen): New function. | ||
| 31 | * unexaix.c, unexcoff.c, unexelf.c, unexhp9k800.c, unexmacosx.c: | ||
| 32 | Include <lisp.h>, for emacs_open. | ||
| 33 | * unexelf.c (fatal): Remove decl; not needed with <lisp.h> included. | ||
| 34 | |||
| 3 | Remove duplicate #include directives. | 35 | Remove duplicate #include directives. |
| 4 | * alloc.c [GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES]: | 36 | * alloc.c [GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES]: |
| 5 | * xfaces.c: | 37 | * xfaces.c: |
diff --git a/src/buffer.c b/src/buffer.c index 64b1bce9b00..94104ef535c 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -4726,7 +4726,7 @@ mmap_init (void) | |||
| 4726 | if (mmap_fd <= 0) | 4726 | if (mmap_fd <= 0) |
| 4727 | { | 4727 | { |
| 4728 | /* No anonymous mmap -- we need the file descriptor. */ | 4728 | /* No anonymous mmap -- we need the file descriptor. */ |
| 4729 | mmap_fd = open ("/dev/zero", O_RDONLY); | 4729 | mmap_fd = emacs_open ("/dev/zero", O_RDONLY, 0); |
| 4730 | if (mmap_fd == -1) | 4730 | if (mmap_fd == -1) |
| 4731 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | 4731 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); |
| 4732 | } | 4732 | } |
diff --git a/src/callproc.c b/src/callproc.c index f0aa8222342..6de8113dc14 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -186,6 +186,12 @@ call_process_cleanup (Lisp_Object arg) | |||
| 186 | return Qnil; | 186 | return Qnil; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | #ifdef DOS_NT | ||
| 190 | static mode_t const default_output_mode = S_IREAD | S_IWRITE; | ||
| 191 | #else | ||
| 192 | static mode_t const default_output_mode = 0666; | ||
| 193 | #endif | ||
| 194 | |||
| 189 | DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0, | 195 | DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0, |
| 190 | doc: /* Call PROGRAM synchronously in separate process. | 196 | doc: /* Call PROGRAM synchronously in separate process. |
| 191 | The remaining arguments are optional. | 197 | The remaining arguments are optional. |
| @@ -407,13 +413,9 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * | |||
| 407 | 413 | ||
| 408 | if (STRINGP (output_file)) | 414 | if (STRINGP (output_file)) |
| 409 | { | 415 | { |
| 410 | #ifdef DOS_NT | ||
| 411 | fd_output = emacs_open (SSDATA (output_file), | 416 | fd_output = emacs_open (SSDATA (output_file), |
| 412 | O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, | 417 | O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, |
| 413 | S_IREAD | S_IWRITE); | 418 | default_output_mode); |
| 414 | #else /* not DOS_NT */ | ||
| 415 | fd_output = creat (SSDATA (output_file), 0666); | ||
| 416 | #endif /* not DOS_NT */ | ||
| 417 | if (fd_output < 0) | 419 | if (fd_output < 0) |
| 418 | { | 420 | { |
| 419 | output_file = DECODE_FILE (output_file); | 421 | output_file = DECODE_FILE (output_file); |
| @@ -492,7 +494,8 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * | |||
| 492 | strcat (tempfile, "/"); | 494 | strcat (tempfile, "/"); |
| 493 | strcat (tempfile, "detmp.XXX"); | 495 | strcat (tempfile, "detmp.XXX"); |
| 494 | mktemp (tempfile); | 496 | mktemp (tempfile); |
| 495 | outfilefd = creat (tempfile, S_IREAD | S_IWRITE); | 497 | outfilefd = emacs_open (tempfile, O_WRONLY | O_CREAT | O_TRUNC, |
| 498 | S_IREAD | S_IWRITE); | ||
| 496 | if (outfilefd < 0) { | 499 | if (outfilefd < 0) { |
| 497 | emacs_close (filefd); | 500 | emacs_close (filefd); |
| 498 | report_file_error ("Opening process output file", | 501 | report_file_error ("Opening process output file", |
| @@ -535,15 +538,9 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) * | |||
| 535 | if (NILP (error_file)) | 538 | if (NILP (error_file)) |
| 536 | fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0); | 539 | fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0); |
| 537 | else if (STRINGP (error_file)) | 540 | else if (STRINGP (error_file)) |
| 538 | { | 541 | fd_error = emacs_open (SSDATA (error_file), |
| 539 | #ifdef DOS_NT | 542 | O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, |
| 540 | fd_error = emacs_open (SSDATA (error_file), | 543 | default_output_mode); |
| 541 | O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, | ||
| 542 | S_IREAD | S_IWRITE); | ||
| 543 | #else /* not DOS_NT */ | ||
| 544 | fd_error = creat (SSDATA (error_file), 0666); | ||
| 545 | #endif /* not DOS_NT */ | ||
| 546 | } | ||
| 547 | 544 | ||
| 548 | if (fd_error < 0) | 545 | if (fd_error < 0) |
| 549 | { | 546 | { |
diff --git a/src/cygw32.c b/src/cygw32.c index a7dbdaed615..bbc3a49fd88 100644 --- a/src/cygw32.c +++ b/src/cygw32.c | |||
| @@ -35,7 +35,7 @@ static void | |||
| 35 | chdir_to_default_directory () | 35 | chdir_to_default_directory () |
| 36 | { | 36 | { |
| 37 | Lisp_Object new_cwd; | 37 | Lisp_Object new_cwd; |
| 38 | int old_cwd_fd = open (".", O_RDONLY | O_DIRECTORY); | 38 | int old_cwd_fd = emacs_open (".", O_RDONLY | O_DIRECTORY, 0); |
| 39 | 39 | ||
| 40 | if (old_cwd_fd == -1) | 40 | if (old_cwd_fd == -1) |
| 41 | error ("could not open current directory: %s", strerror (errno)); | 41 | error ("could not open current directory: %s", strerror (errno)); |
diff --git a/src/dispnew.c b/src/dispnew.c index b4ca654a8f7..31b8a1310ea 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -22,7 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 22 | 22 | ||
| 23 | #define DISPEXTERN_INLINE EXTERN_INLINE | 23 | #define DISPEXTERN_INLINE EXTERN_INLINE |
| 24 | 24 | ||
| 25 | #include <stdio.h> | 25 | #include "sysstdio.h" |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| 27 | 27 | ||
| 28 | #include "lisp.h" | 28 | #include "lisp.h" |
| @@ -5605,17 +5605,17 @@ FILE = nil means just close any termscript file currently open. */) | |||
| 5605 | tty = CURTTY (); | 5605 | tty = CURTTY (); |
| 5606 | 5606 | ||
| 5607 | if (tty->termscript != 0) | 5607 | if (tty->termscript != 0) |
| 5608 | { | 5608 | { |
| 5609 | block_input (); | 5609 | block_input (); |
| 5610 | fclose (tty->termscript); | 5610 | fclose (tty->termscript); |
| 5611 | unblock_input (); | 5611 | tty->termscript = 0; |
| 5612 | } | 5612 | unblock_input (); |
| 5613 | tty->termscript = 0; | 5613 | } |
| 5614 | 5614 | ||
| 5615 | if (! NILP (file)) | 5615 | if (! NILP (file)) |
| 5616 | { | 5616 | { |
| 5617 | file = Fexpand_file_name (file, Qnil); | 5617 | file = Fexpand_file_name (file, Qnil); |
| 5618 | tty->termscript = fopen (SSDATA (file), "w"); | 5618 | tty->termscript = emacs_fopen (SSDATA (file), "w"); |
| 5619 | if (tty->termscript == 0) | 5619 | if (tty->termscript == 0) |
| 5620 | report_file_error ("Opening termscript", Fcons (file, Qnil)); | 5620 | report_file_error ("Opening termscript", Fcons (file, Qnil)); |
| 5621 | } | 5621 | } |
diff --git a/src/emacs.c b/src/emacs.c index 4b709527ff0..6ba01d1a443 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -2236,7 +2236,7 @@ from the parent process and its tty file descriptors. */) | |||
| 2236 | error ("This function can only be called after loading the init files"); | 2236 | error ("This function can only be called after loading the init files"); |
| 2237 | 2237 | ||
| 2238 | /* Get rid of stdin, stdout and stderr. */ | 2238 | /* Get rid of stdin, stdout and stderr. */ |
| 2239 | nfd = open ("/dev/null", O_RDWR); | 2239 | nfd = emacs_open ("/dev/null", O_RDWR, 0); |
| 2240 | err |= nfd < 0; | 2240 | err |= nfd < 0; |
| 2241 | err |= dup2 (nfd, 0) < 0; | 2241 | err |= dup2 (nfd, 0) < 0; |
| 2242 | err |= dup2 (nfd, 1) < 0; | 2242 | err |= dup2 (nfd, 1) < 0; |
diff --git a/src/fileio.c b/src/fileio.c index 0ba7f85da2c..89ae89e1613 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -20,7 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | #include <config.h> | 20 | #include <config.h> |
| 21 | #include <limits.h> | 21 | #include <limits.h> |
| 22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
| 23 | #include <stdio.h> | 23 | #include "sysstdio.h" |
| 24 | #include <sys/types.h> | 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
| 26 | #include <unistd.h> | 26 | #include <unistd.h> |
| @@ -5618,7 +5618,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */) | |||
| 5618 | UNGCPRO; | 5618 | UNGCPRO; |
| 5619 | } | 5619 | } |
| 5620 | 5620 | ||
| 5621 | stream = fopen (SSDATA (listfile), "w"); | 5621 | stream = emacs_fopen (SSDATA (listfile), "w"); |
| 5622 | } | 5622 | } |
| 5623 | 5623 | ||
| 5624 | record_unwind_protect (do_auto_save_unwind, | 5624 | record_unwind_protect (do_auto_save_unwind, |
diff --git a/src/image.c b/src/image.c index a3e103f9559..7ecd59d27b4 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License | |||
| 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 | ||
| 20 | #include <config.h> | 20 | #include <config.h> |
| 21 | #include <stdio.h> | 21 | #include "sysstdio.h" |
| 22 | #include <unistd.h> | 22 | #include <unistd.h> |
| 23 | 23 | ||
| 24 | #ifdef HAVE_PNG | 24 | #ifdef HAVE_PNG |
| @@ -2274,7 +2274,7 @@ x_find_image_file (Lisp_Object file) | |||
| 2274 | static unsigned char * | 2274 | static unsigned char * |
| 2275 | slurp_file (char *file, ptrdiff_t *size) | 2275 | slurp_file (char *file, ptrdiff_t *size) |
| 2276 | { | 2276 | { |
| 2277 | FILE *fp = fopen (file, "rb"); | 2277 | FILE *fp = emacs_fopen (file, "rb"); |
| 2278 | unsigned char *buf = NULL; | 2278 | unsigned char *buf = NULL; |
| 2279 | struct stat st; | 2279 | struct stat st; |
| 2280 | 2280 | ||
| @@ -5723,7 +5723,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) | |||
| 5723 | } | 5723 | } |
| 5724 | 5724 | ||
| 5725 | /* Open the image file. */ | 5725 | /* Open the image file. */ |
| 5726 | fp = fopen (SSDATA (file), "rb"); | 5726 | fp = emacs_fopen (SSDATA (file), "rb"); |
| 5727 | if (!fp) | 5727 | if (!fp) |
| 5728 | { | 5728 | { |
| 5729 | image_error ("Cannot open image file `%s'", file, Qnil); | 5729 | image_error ("Cannot open image file `%s'", file, Qnil); |
| @@ -6484,7 +6484,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6484 | return 0; | 6484 | return 0; |
| 6485 | } | 6485 | } |
| 6486 | 6486 | ||
| 6487 | fp = fopen (SSDATA (file), "rb"); | 6487 | fp = emacs_fopen (SSDATA (file), "rb"); |
| 6488 | if (fp == NULL) | 6488 | if (fp == NULL) |
| 6489 | { | 6489 | { |
| 6490 | image_error ("Cannot open `%s'", file, Qnil); | 6490 | image_error ("Cannot open `%s'", file, Qnil); |
diff --git a/src/keyboard.c b/src/keyboard.c index e6094a939b9..39535f5cd71 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -23,7 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | #define BLOCKINPUT_INLINE EXTERN_INLINE | 23 | #define BLOCKINPUT_INLINE EXTERN_INLINE |
| 24 | #define KEYBOARD_INLINE EXTERN_INLINE | 24 | #define KEYBOARD_INLINE EXTERN_INLINE |
| 25 | 25 | ||
| 26 | #include <stdio.h> | 26 | #include "sysstdio.h" |
| 27 | 27 | ||
| 28 | #include "lisp.h" | 28 | #include "lisp.h" |
| 29 | #include "termchar.h" | 29 | #include "termchar.h" |
| @@ -10129,7 +10129,7 @@ The file will be closed when Emacs exits. */) | |||
| 10129 | if (!NILP (file)) | 10129 | if (!NILP (file)) |
| 10130 | { | 10130 | { |
| 10131 | file = Fexpand_file_name (file, Qnil); | 10131 | file = Fexpand_file_name (file, Qnil); |
| 10132 | dribble = fopen (SSDATA (file), "w"); | 10132 | dribble = emacs_fopen (SSDATA (file), "w"); |
| 10133 | if (dribble == 0) | 10133 | if (dribble == 0) |
| 10134 | report_file_error ("Opening dribble", Fcons (file, Qnil)); | 10134 | report_file_error ("Opening dribble", Fcons (file, Qnil)); |
| 10135 | } | 10135 | } |
diff --git a/src/lread.c b/src/lread.c index 5f7b2cbdbe2..06badce12be 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -20,7 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | #include <stdio.h> | 23 | #include "sysstdio.h" |
| 24 | #include <sys/types.h> | 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
| 26 | #include <sys/file.h> | 26 | #include <sys/file.h> |
| @@ -1297,7 +1297,7 @@ Return t if the file exists and loads successfully. */) | |||
| 1297 | if (fd >= 0) | 1297 | if (fd >= 0) |
| 1298 | { | 1298 | { |
| 1299 | emacs_close (fd); | 1299 | emacs_close (fd); |
| 1300 | stream = fopen (SSDATA (efound), fmode); | 1300 | stream = emacs_fopen (SSDATA (efound), fmode); |
| 1301 | } | 1301 | } |
| 1302 | else | 1302 | else |
| 1303 | stream = NULL; | 1303 | stream = NULL; |
diff --git a/src/print.c b/src/print.c index b1eec4c48d4..a16f3b32f46 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -20,7 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | #include <stdio.h> | 23 | #include "sysstdio.h" |
| 24 | 24 | ||
| 25 | #include "lisp.h" | 25 | #include "lisp.h" |
| 26 | #include "character.h" | 26 | #include "character.h" |
| @@ -765,7 +765,7 @@ append to existing target file. */) | |||
| 765 | { | 765 | { |
| 766 | file = Fexpand_file_name (file, Qnil); | 766 | file = Fexpand_file_name (file, Qnil); |
| 767 | initial_stderr_stream = stderr; | 767 | initial_stderr_stream = stderr; |
| 768 | stderr = fopen (SSDATA (file), NILP (append) ? "w" : "a"); | 768 | stderr = emacs_fopen (SSDATA (file), NILP (append) ? "w" : "a"); |
| 769 | if (stderr == NULL) | 769 | if (stderr == NULL) |
| 770 | { | 770 | { |
| 771 | stderr = initial_stderr_stream; | 771 | stderr = initial_stderr_stream; |
diff --git a/src/sysdep.c b/src/sysdep.c index 11b2dbfd617..91e941a2050 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -22,7 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 22 | #define SYSTIME_INLINE EXTERN_INLINE | 22 | #define SYSTIME_INLINE EXTERN_INLINE |
| 23 | 23 | ||
| 24 | #include <execinfo.h> | 24 | #include <execinfo.h> |
| 25 | #include <stdio.h> | 25 | #include "sysstdio.h" |
| 26 | #ifdef HAVE_PWD_H | 26 | #ifdef HAVE_PWD_H |
| 27 | #include <pwd.h> | 27 | #include <pwd.h> |
| 28 | #include <grp.h> | 28 | #include <grp.h> |
| @@ -2151,15 +2151,29 @@ emacs_abort (void) | |||
| 2151 | } | 2151 | } |
| 2152 | #endif | 2152 | #endif |
| 2153 | 2153 | ||
| 2154 | /* Open FILE for Emacs use, using open flags OFLAG and mode MODE. | ||
| 2155 | Do not fail merely because the open was interrupted by a signal. | ||
| 2156 | Allow the user to quit. */ | ||
| 2157 | |||
| 2154 | int | 2158 | int |
| 2155 | emacs_open (const char *path, int oflag, int mode) | 2159 | emacs_open (const char *file, int oflags, int mode) |
| 2156 | { | 2160 | { |
| 2157 | register int rtnval; | 2161 | int fd; |
| 2162 | while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR) | ||
| 2163 | QUIT; | ||
| 2164 | return fd; | ||
| 2165 | } | ||
| 2158 | 2166 | ||
| 2159 | while ((rtnval = open (path, oflag, mode)) == -1 | 2167 | /* Open FILE as a stream for Emacs use, with mode MODE. |
| 2160 | && (errno == EINTR)) | 2168 | Act like emacs_open with respect to threads, signals, and quits. */ |
| 2169 | |||
| 2170 | FILE * | ||
| 2171 | emacs_fopen (char const *file, char const *mode) | ||
| 2172 | { | ||
| 2173 | FILE *fp; | ||
| 2174 | while (! (fp = fopen (file, mode)) && errno == EINTR) | ||
| 2161 | QUIT; | 2175 | QUIT; |
| 2162 | return (rtnval); | 2176 | return fp; |
| 2163 | } | 2177 | } |
| 2164 | 2178 | ||
| 2165 | int | 2179 | int |
| @@ -2637,7 +2651,7 @@ get_up_time (void) | |||
| 2637 | EMACS_TIME up = make_emacs_time (0, 0); | 2651 | EMACS_TIME up = make_emacs_time (0, 0); |
| 2638 | 2652 | ||
| 2639 | block_input (); | 2653 | block_input (); |
| 2640 | fup = fopen ("/proc/uptime", "r"); | 2654 | fup = emacs_fopen ("/proc/uptime", "r"); |
| 2641 | 2655 | ||
| 2642 | if (fup) | 2656 | if (fup) |
| 2643 | { | 2657 | { |
| @@ -2682,7 +2696,7 @@ procfs_ttyname (int rdev) | |||
| 2682 | char name[PATH_MAX]; | 2696 | char name[PATH_MAX]; |
| 2683 | 2697 | ||
| 2684 | block_input (); | 2698 | block_input (); |
| 2685 | fdev = fopen ("/proc/tty/drivers", "r"); | 2699 | fdev = emacs_fopen ("/proc/tty/drivers", "r"); |
| 2686 | 2700 | ||
| 2687 | if (fdev) | 2701 | if (fdev) |
| 2688 | { | 2702 | { |
| @@ -2724,7 +2738,7 @@ procfs_get_total_memory (void) | |||
| 2724 | unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */ | 2738 | unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */ |
| 2725 | 2739 | ||
| 2726 | block_input (); | 2740 | block_input (); |
| 2727 | fmem = fopen ("/proc/meminfo", "r"); | 2741 | fmem = emacs_fopen ("/proc/meminfo", "r"); |
| 2728 | 2742 | ||
| 2729 | if (fmem) | 2743 | if (fmem) |
| 2730 | { | 2744 | { |
diff --git a/src/sysstdio.h b/src/sysstdio.h new file mode 100644 index 00000000000..e9dfb696059 --- /dev/null +++ b/src/sysstdio.h | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | extern FILE *emacs_fopen (char const *, char const *); | ||
diff --git a/src/term.c b/src/term.c index 0bcef55947a..39d143564c6 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -2479,7 +2479,7 @@ term_mouse_moveto (int x, int y) | |||
| 2479 | const char *name; | 2479 | const char *name; |
| 2480 | int fd; | 2480 | int fd; |
| 2481 | name = (const char *) ttyname (0); | 2481 | name = (const char *) ttyname (0); |
| 2482 | fd = open (name, O_WRONLY); | 2482 | fd = emacs_open (name, O_WRONLY, 0); |
| 2483 | SOME_FUNCTION (x, y, fd); | 2483 | SOME_FUNCTION (x, y, fd); |
| 2484 | close (fd); | 2484 | close (fd); |
| 2485 | last_mouse_x = x; | 2485 | last_mouse_x = x; |
diff --git a/src/termcap.c b/src/termcap.c index 99bbfce27f5..7256eef9e81 100644 --- a/src/termcap.c +++ b/src/termcap.c | |||
| @@ -427,11 +427,7 @@ tgetent (char *bp, const char *name) | |||
| 427 | 427 | ||
| 428 | /* Here we know we must search a file and termcap_name has its name. */ | 428 | /* Here we know we must search a file and termcap_name has its name. */ |
| 429 | 429 | ||
| 430 | #ifdef MSDOS | 430 | fd = emacs_open (termcap_name, O_RDONLY | O_TEXT, 0); |
| 431 | fd = open (termcap_name, O_RDONLY|O_TEXT, 0); | ||
| 432 | #else | ||
| 433 | fd = open (termcap_name, O_RDONLY, 0); | ||
| 434 | #endif | ||
| 435 | if (fd < 0) | 431 | if (fd < 0) |
| 436 | return -1; | 432 | return -1; |
| 437 | 433 | ||
diff --git a/src/unexaix.c b/src/unexaix.c index 44a824b8c12..204f6cf4ad3 100644 --- a/src/unexaix.c +++ b/src/unexaix.c | |||
| @@ -42,6 +42,7 @@ what you give them. Help stamp out software-hoarding! */ | |||
| 42 | 42 | ||
| 43 | #include <config.h> | 43 | #include <config.h> |
| 44 | #include "unexec.h" | 44 | #include "unexec.h" |
| 45 | #include "lisp.h" | ||
| 45 | 46 | ||
| 46 | #define PERROR(file) report_error (file, new) | 47 | #define PERROR(file) report_error (file, new) |
| 47 | #include <a.out.h> | 48 | #include <a.out.h> |
| @@ -132,11 +133,11 @@ unexec (const char *new_name, const char *a_name) | |||
| 132 | { | 133 | { |
| 133 | int new = -1, a_out = -1; | 134 | int new = -1, a_out = -1; |
| 134 | 135 | ||
| 135 | if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | 136 | if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0) |
| 136 | { | 137 | { |
| 137 | PERROR (a_name); | 138 | PERROR (a_name); |
| 138 | } | 139 | } |
| 139 | if ((new = creat (new_name, 0666)) < 0) | 140 | if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) |
| 140 | { | 141 | { |
| 141 | PERROR (new_name); | 142 | PERROR (new_name); |
| 142 | } | 143 | } |
| @@ -503,7 +504,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) | |||
| 503 | if (!lnnoptr || !f_hdr.f_symptr) | 504 | if (!lnnoptr || !f_hdr.f_symptr) |
| 504 | return 0; | 505 | return 0; |
| 505 | 506 | ||
| 506 | if ((new = open (new_name, O_RDWR)) < 0) | 507 | if ((new = emacs_open (new_name, O_RDWR, 0)) < 0) |
| 507 | { | 508 | { |
| 508 | PERROR (new_name); | 509 | PERROR (new_name); |
| 509 | return -1; | 510 | return -1; |
diff --git a/src/unexcoff.c b/src/unexcoff.c index 2e662a34145..e79821251ba 100644 --- a/src/unexcoff.c +++ b/src/unexcoff.c | |||
| @@ -52,6 +52,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 52 | 52 | ||
| 53 | #include <config.h> | 53 | #include <config.h> |
| 54 | #include "unexec.h" | 54 | #include "unexec.h" |
| 55 | #include "lisp.h" | ||
| 55 | 56 | ||
| 56 | #define PERROR(file) report_error (file, new) | 57 | #define PERROR(file) report_error (file, new) |
| 57 | 58 | ||
| @@ -486,7 +487,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name) | |||
| 486 | #ifdef MSDOS | 487 | #ifdef MSDOS |
| 487 | if ((new = writedesc) < 0) | 488 | if ((new = writedesc) < 0) |
| 488 | #else | 489 | #else |
| 489 | if ((new = open (new_name, O_RDWR)) < 0) | 490 | if ((new = emacs_open (new_name, O_RDWR, 0)) < 0) |
| 490 | #endif | 491 | #endif |
| 491 | { | 492 | { |
| 492 | PERROR (new_name); | 493 | PERROR (new_name); |
| @@ -525,11 +526,11 @@ unexec (const char *new_name, const char *a_name) | |||
| 525 | { | 526 | { |
| 526 | int new = -1, a_out = -1; | 527 | int new = -1, a_out = -1; |
| 527 | 528 | ||
| 528 | if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | 529 | if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0) |
| 529 | { | 530 | { |
| 530 | PERROR (a_name); | 531 | PERROR (a_name); |
| 531 | } | 532 | } |
| 532 | if ((new = creat (new_name, 0666)) < 0) | 533 | if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) |
| 533 | { | 534 | { |
| 534 | PERROR (new_name); | 535 | PERROR (new_name); |
| 535 | } | 536 | } |
diff --git a/src/unexcw.c b/src/unexcw.c index 1290c28d245..0312a7328fb 100644 --- a/src/unexcw.c +++ b/src/unexcw.c | |||
| @@ -20,8 +20,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | #include "unexec.h" | 22 | #include "unexec.h" |
| 23 | #include "lisp.h" | ||
| 23 | 24 | ||
| 24 | #include <lisp.h> | ||
| 25 | #include <stdio.h> | 25 | #include <stdio.h> |
| 26 | #include <fcntl.h> | 26 | #include <fcntl.h> |
| 27 | #include <a.out.h> | 27 | #include <a.out.h> |
| @@ -298,9 +298,9 @@ unexec (const char *outfile, const char *infile) | |||
| 298 | infile = add_exe_suffix_if_necessary (infile, infile_buffer); | 298 | infile = add_exe_suffix_if_necessary (infile, infile_buffer); |
| 299 | outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer); | 299 | outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer); |
| 300 | 300 | ||
| 301 | fd_in = open (infile, O_RDONLY | O_BINARY); | 301 | fd_in = emacs_open (infile, O_RDONLY | O_BINARY, 0); |
| 302 | assert (fd_in >= 0); | 302 | assert (fd_in >= 0); |
| 303 | fd_out = open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755); | 303 | fd_out = emacs_open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755); |
| 304 | assert (fd_out >= 0); | 304 | assert (fd_out >= 0); |
| 305 | for (;;) | 305 | for (;;) |
| 306 | { | 306 | { |
diff --git a/src/unexelf.c b/src/unexelf.c index 4e50bb86367..28847157e40 100644 --- a/src/unexelf.c +++ b/src/unexelf.c | |||
| @@ -386,9 +386,8 @@ temacs: | |||
| 386 | Instead we read the whole file, modify it, and write it out. */ | 386 | Instead we read the whole file, modify it, and write it out. */ |
| 387 | 387 | ||
| 388 | #include <config.h> | 388 | #include <config.h> |
| 389 | #include <unexec.h> | 389 | #include "unexec.h" |
| 390 | 390 | #include "lisp.h" | |
| 391 | extern _Noreturn void fatal (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); | ||
| 392 | 391 | ||
| 393 | #include <errno.h> | 392 | #include <errno.h> |
| 394 | #include <fcntl.h> | 393 | #include <fcntl.h> |
| @@ -672,7 +671,7 @@ unexec (const char *new_name, const char *old_name) | |||
| 672 | /* Open the old file, allocate a buffer of the right size, and read | 671 | /* Open the old file, allocate a buffer of the right size, and read |
| 673 | in the file contents. */ | 672 | in the file contents. */ |
| 674 | 673 | ||
| 675 | old_file = open (old_name, O_RDONLY); | 674 | old_file = emacs_open (old_name, O_RDONLY, 0); |
| 676 | 675 | ||
| 677 | if (old_file < 0) | 676 | if (old_file < 0) |
| 678 | fatal ("Can't open %s for reading: %s", old_name, strerror (errno)); | 677 | fatal ("Can't open %s for reading: %s", old_name, strerror (errno)); |
| @@ -681,7 +680,7 @@ unexec (const char *new_name, const char *old_name) | |||
| 681 | fatal ("Can't fstat (%s): %s", old_name, strerror (errno)); | 680 | fatal ("Can't fstat (%s): %s", old_name, strerror (errno)); |
| 682 | 681 | ||
| 683 | #if MAP_ANON == 0 | 682 | #if MAP_ANON == 0 |
| 684 | mmap_fd = open ("/dev/zero", O_RDONLY); | 683 | mmap_fd = emacs_open ("/dev/zero", O_RDONLY, 0); |
| 685 | if (mmap_fd < 0) | 684 | if (mmap_fd < 0) |
| 686 | fatal ("Can't open /dev/zero for reading: %s", strerror (errno)); | 685 | fatal ("Can't open /dev/zero for reading: %s", strerror (errno)); |
| 687 | #endif | 686 | #endif |
| @@ -801,7 +800,7 @@ unexec (const char *new_name, const char *old_name) | |||
| 801 | the image of the new file. Set pointers to various interesting | 800 | the image of the new file. Set pointers to various interesting |
| 802 | objects. */ | 801 | objects. */ |
| 803 | 802 | ||
| 804 | new_file = open (new_name, O_RDWR | O_CREAT, 0666); | 803 | new_file = emacs_open (new_name, O_RDWR | O_CREAT, 0666); |
| 805 | if (new_file < 0) | 804 | if (new_file < 0) |
| 806 | fatal ("Can't creat (%s): %s", new_name, strerror (errno)); | 805 | fatal ("Can't creat (%s): %s", new_name, strerror (errno)); |
| 807 | 806 | ||
diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c index ce65faffd4e..0f6eb87ee01 100644 --- a/src/unexhp9k800.c +++ b/src/unexhp9k800.c | |||
| @@ -51,6 +51,7 @@ | |||
| 51 | 51 | ||
| 52 | #include <config.h> | 52 | #include <config.h> |
| 53 | #include "unexec.h" | 53 | #include "unexec.h" |
| 54 | #include "lisp.h" | ||
| 54 | 55 | ||
| 55 | #include <stdio.h> | 56 | #include <stdio.h> |
| 56 | #include <fcntl.h> | 57 | #include <fcntl.h> |
| @@ -268,10 +269,10 @@ unexec (const char *new_name, /* name of the new a.out file to be created * | |||
| 268 | intact. NOT implemented. */ | 269 | intact. NOT implemented. */ |
| 269 | 270 | ||
| 270 | /* Open the input and output a.out files */ | 271 | /* Open the input and output a.out files */ |
| 271 | old = open (old_name, O_RDONLY); | 272 | old = emacs_open (old_name, O_RDONLY, 0); |
| 272 | if (old < 0) | 273 | if (old < 0) |
| 273 | { perror (old_name); exit (1); } | 274 | { perror (old_name); exit (1); } |
| 274 | new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); | 275 | new = emacs_open (new_name, O_CREAT | O_RDWR | O_TRUNC, 0777); |
| 275 | if (new < 0) | 276 | if (new < 0) |
| 276 | { perror (new_name); exit (1); } | 277 | { perror (new_name); exit (1); } |
| 277 | 278 | ||
diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 8d4e636fa5c..2bc6de177eb 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c | |||
| @@ -97,6 +97,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 97 | #undef free | 97 | #undef free |
| 98 | 98 | ||
| 99 | #include "unexec.h" | 99 | #include "unexec.h" |
| 100 | #include "lisp.h" | ||
| 100 | 101 | ||
| 101 | #include <stdio.h> | 102 | #include <stdio.h> |
| 102 | #include <fcntl.h> | 103 | #include <fcntl.h> |
| @@ -1322,13 +1323,13 @@ unexec (const char *outfile, const char *infile) | |||
| 1322 | unexec_error ("Unexec from a dumped executable is not supported."); | 1323 | unexec_error ("Unexec from a dumped executable is not supported."); |
| 1323 | 1324 | ||
| 1324 | pagesize = getpagesize (); | 1325 | pagesize = getpagesize (); |
| 1325 | infd = open (infile, O_RDONLY, 0); | 1326 | infd = emacs_open (infile, O_RDONLY, 0); |
| 1326 | if (infd < 0) | 1327 | if (infd < 0) |
| 1327 | { | 1328 | { |
| 1328 | unexec_error ("cannot open input file `%s'", infile); | 1329 | unexec_error ("cannot open input file `%s'", infile); |
| 1329 | } | 1330 | } |
| 1330 | 1331 | ||
| 1331 | outfd = open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755); | 1332 | outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755); |
| 1332 | if (outfd < 0) | 1333 | if (outfd < 0) |
| 1333 | { | 1334 | { |
| 1334 | close (infd); | 1335 | close (infd); |
diff --git a/src/w32term.c b/src/w32term.c index fcd5886d5c9..c9951ca1d52 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -6621,7 +6621,7 @@ w32_initialize (void) | |||
| 6621 | } | 6621 | } |
| 6622 | 6622 | ||
| 6623 | #ifdef CYGWIN | 6623 | #ifdef CYGWIN |
| 6624 | if ((w32_message_fd = open ("/dev/windows", O_RDWR | O_CLOEXEC)) == -1) | 6624 | if ((w32_message_fd = emacs_open ("/dev/windows", O_RDWR, 0)) == -1) |
| 6625 | fatal ("opening /dev/windows: %s", strerror (errno)); | 6625 | fatal ("opening /dev/windows: %s", strerror (errno)); |
| 6626 | #endif /* CYGWIN */ | 6626 | #endif /* CYGWIN */ |
| 6627 | 6627 | ||
diff --git a/src/xfaces.c b/src/xfaces.c index 0c627d7f9ee..4b42cb7dc40 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -200,7 +200,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 200 | used to fill in unspecified attributes of the default face. */ | 200 | used to fill in unspecified attributes of the default face. */ |
| 201 | 201 | ||
| 202 | #include <config.h> | 202 | #include <config.h> |
| 203 | #include <stdio.h> | 203 | #include "sysstdio.h" |
| 204 | #include <sys/types.h> | 204 | #include <sys/types.h> |
| 205 | #include <sys/stat.h> | 205 | #include <sys/stat.h> |
| 206 | 206 | ||
| @@ -6290,7 +6290,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */) | |||
| 6290 | CHECK_STRING (filename); | 6290 | CHECK_STRING (filename); |
| 6291 | abspath = Fexpand_file_name (filename, Qnil); | 6291 | abspath = Fexpand_file_name (filename, Qnil); |
| 6292 | 6292 | ||
| 6293 | fp = fopen (SSDATA (abspath), "rt"); | 6293 | fp = emacs_fopen (SSDATA (abspath), "rt"); |
| 6294 | if (fp) | 6294 | if (fp) |
| 6295 | { | 6295 | { |
| 6296 | char buf[512]; | 6296 | char buf[512]; |