aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-10-20 15:37:19 +0100
committerRon Yorston <rmy@pobox.com>2016-10-20 15:37:19 +0100
commite135a80b90661689b9912d708b1a40344844192e (patch)
tree8dc3437fb0be312e6a05138219e7846b94f28b90
parent3528bee569f518dcb66e1343dd808b437499db84 (diff)
downloadbusybox-w32-e135a80b90661689b9912d708b1a40344844192e.tar.gz
busybox-w32-e135a80b90661689b9912d708b1a40344844192e.tar.bz2
busybox-w32-e135a80b90661689b9912d708b1a40344844192e.zip
diff: change handling of temporary files for WIN32
If it isn't possible to seek in an input file diff creates a temporary file to store the text. On Windows we can't assume that /tmp exists and we need to unlink the temporary files at the end of processing, not the start.
-rw-r--r--editors/diff.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 75229ad8c..5c8a55b93 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -724,6 +724,10 @@ static int diffreg(char *file[2])
724 FILE *fp[2]; 724 FILE *fp[2];
725 bool binary = false, differ = false; 725 bool binary = false, differ = false;
726 int status = STATUS_SAME, i; 726 int status = STATUS_SAME, i;
727#if ENABLE_PLATFORM_MINGW32
728 char *tmpfile[2] = { NULL, NULL };
729 char *tmpdir;
730#endif
727 731
728 fp[0] = stdin; 732 fp[0] = stdin;
729 fp[1] = stdin; 733 fp[1] = stdin;
@@ -735,10 +739,19 @@ static int diffreg(char *file[2])
735 * When we meet non-seekable file, we must make a temp copy. 739 * When we meet non-seekable file, we must make a temp copy.
736 */ 740 */
737 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { 741 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
742#if !ENABLE_PLATFORM_MINGW32
738 char name[] = "/tmp/difXXXXXX"; 743 char name[] = "/tmp/difXXXXXX";
739 int fd_tmp = xmkstemp(name); 744 int fd_tmp = xmkstemp(name);
740 745
741 unlink(name); 746 unlink(name);
747#else
748 int fd_tmp;
749
750 if (!(tmpdir=getenv("TMP")) && !(tmpdir=getenv("TEMP")))
751 goto out;
752 tmpfile[i] = xasprintf("%s/difXXXXXX", tmpdir);
753 fd_tmp = xmkstemp(tmpfile[i]);
754#endif
742 if (bb_copyfd_eof(fd, fd_tmp) < 0) 755 if (bb_copyfd_eof(fd, fd_tmp) < 0)
743 xfunc_die(); 756 xfunc_die();
744 if (fd != STDIN_FILENO) 757 if (fd != STDIN_FILENO)
@@ -781,6 +794,14 @@ static int diffreg(char *file[2])
781out: 794out:
782 fclose_if_not_stdin(fp[0]); 795 fclose_if_not_stdin(fp[0]);
783 fclose_if_not_stdin(fp[1]); 796 fclose_if_not_stdin(fp[1]);
797#if ENABLE_PLATFORM_MINGW32
798 for (i = 0; i < 2; i++) {
799 if (tmpfile[i]) {
800 unlink(tmpfile[i]);
801 free(tmpfile[i]);
802 }
803 }
804#endif
784 805
785 return status; 806 return status;
786} 807}