aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
authorEli Zaretskii <[email protected]>2011-05-07 14:25:05 +0300
committerEli Zaretskii <[email protected]>2011-05-07 14:25:05 +0300
commit888c9e865f8c9faea62621519da7e42ba1b7adbf (patch)
treea7dc81f1b07e8abb02d1463425536425b77c2040 /src/callproc.c
parent75c0d28a6a89e31172e2533ef9638c75af02dada (diff)
Fix changes in 2011-05-01T00:04:[email protected] for MS-DOS.
src/callproc.c (call_process_cleanup): Don't close and unlink the temporary file if Fcall_process didn't create it in the first place. (Fcall_process): Don't create tempfile if stdout of the child process will be redirected to a file specified with `:file'. Don't try to re-open tempfile in that case, and set fd[0] to -1 as cue to call_process_cleanup not to close that handle.
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 946670320c..a966a26b93 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -114,6 +114,7 @@ call_process_cleanup (Lisp_Object arg)
Lisp_Object fdpid = Fcdr (arg);
#if defined (MSDOS)
Lisp_Object file;
+ int fd;
#else
int pid;
#endif
@@ -122,9 +123,13 @@ call_process_cleanup (Lisp_Object arg)
#if defined (MSDOS)
/* for MSDOS fdpid is really (fd . tempfile) */
+ fd = XFASTINT (Fcar (fdpid));
file = Fcdr (fdpid);
- emacs_close (XFASTINT (Fcar (fdpid)));
- if (strcmp (SDATA (file), NULL_DEVICE) != 0)
+ /* FD is -1 and FILE is "" when we didn't actually create a
+ temporary file in call-process. */
+ if (fd >= 0)
+ emacs_close (fd);
+ if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0'))
unlink (SDATA (file));
#else /* not MSDOS */
pid = XFASTINT (Fcdr (fdpid));
@@ -199,7 +204,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
Lisp_Object error_file;
Lisp_Object output_file = Qnil;
#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
- char *outf, *tempfile;
+ char *outf, *tempfile = NULL;
int outfilefd;
#endif
int fd_output = -1;
@@ -439,22 +444,23 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
new_argv[0] = SDATA (path);
#ifdef MSDOS /* MW, July 1993 */
- if ((outf = egetenv ("TMPDIR")))
- strcpy (tempfile = alloca (strlen (outf) + 20), outf);
- else
- {
- tempfile = alloca (20);
- *tempfile = '\0';
- }
- dostounix_filename (tempfile);
- if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
- strcat (tempfile, "/");
- strcat (tempfile, "detmp.XXX");
- mktemp (tempfile);
- /* If we're redirecting STDOUT to a file, this is already opened. */
+ /* If we're redirecting STDOUT to a file, that file is already open
+ on fd_output. */
if (fd_output < 0)
{
+ if ((outf = egetenv ("TMPDIR")))
+ strcpy (tempfile = alloca (strlen (outf) + 20), outf);
+ else
+ {
+ tempfile = alloca (20);
+ *tempfile = '\0';
+ }
+ dostounix_filename (tempfile);
+ if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
+ strcat (tempfile, "/");
+ strcat (tempfile, "detmp.XXX");
+ mktemp (tempfile);
outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
if (outfilefd < 0) {
emacs_close (filefd);
@@ -561,15 +567,21 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
if (fd_error != outfilefd)
emacs_close (fd_error);
fd1 = -1; /* No harm in closing that one! */
- /* Since CRLF is converted to LF within `decode_coding', we can
- always open a file with binary mode. */
- fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
- if (fd[0] < 0)
+ if (tempfile)
{
- unlink (tempfile);
- emacs_close (filefd);
- report_file_error ("Cannot re-open temporary file", Qnil);
+ /* Since CRLF is converted to LF within `decode_coding', we
+ can always open a file with binary mode. */
+ fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
+ if (fd[0] < 0)
+ {
+ unlink (tempfile);
+ emacs_close (filefd);
+ report_file_error ("Cannot re-open temporary file",
+ Fcons (tempfile, Qnil));
+ }
}
+ else
+ fd[0] = -1; /* We are not going to read from tempfile. */
#else /* not MSDOS */
#ifdef WINDOWSNT
pid = child_setup (filefd, fd1, fd_error, (char **) new_argv,
@@ -676,7 +688,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
record_unwind_protect (call_process_cleanup,
Fcons (Fcurrent_buffer (),
Fcons (make_number (fd[0]),
- build_string (tempfile))));
+ build_string (tempfile ? tempfile : ""))));
#else
record_unwind_protect (call_process_cleanup,
Fcons (Fcurrent_buffer (),