aboutsummaryrefslogtreecommitdiff
path: root/editors/diff.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:28:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:28:47 +0000
commite9d67a81c8c8ca0d256670929353b9a8d3b18563 (patch)
tree27075fa906345b7765f9a0272c3ec075923b3686 /editors/diff.c
parent7fe0ebac5f22a810ee25ea182582ee71d6bf86b2 (diff)
downloadbusybox-w32-e9d67a81c8c8ca0d256670929353b9a8d3b18563.tar.gz
busybox-w32-e9d67a81c8c8ca0d256670929353b9a8d3b18563.tar.bz2
busybox-w32-e9d67a81c8c8ca0d256670929353b9a8d3b18563.zip
diff: fix small bug; don't make a copy for "/dev/null" case
Diffstat (limited to 'editors/diff.c')
-rw-r--r--editors/diff.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 7a6422564..27c8365cc 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -283,7 +283,7 @@ static char *make_temp(FILE *f, struct stat *sb)
283 char *name; 283 char *name;
284 int fd; 284 int fd;
285 285
286 if (S_ISREG(sb->st_mode)) 286 if (S_ISREG(sb->st_mode) || S_ISBLK(sb->st_mode))
287 return NULL; 287 return NULL;
288 name = xstrdup("/tmp/difXXXXXX"); 288 name = xstrdup("/tmp/difXXXXXX");
289 fd = mkstemp(name); 289 fd = mkstemp(name);
@@ -312,9 +312,15 @@ static NOINLINE int files_differ(FILE *f1, FILE *f2, int flags)
312{ 312{
313 size_t i, j; 313 size_t i, j;
314 314
315 /* Prevent making copies for "/dev/null" (too common) */
316 tempname1 = tempname2 = NULL;
317 if (flags & (D_EMPTY1 | D_EMPTY2)) {
318 return 1;
319 }
320 /* Deal with input from pipes etc */
315 tempname1 = make_temp(f1, &stb1); 321 tempname1 = make_temp(f1, &stb1);
316 tempname2 = make_temp(f2, &stb2); 322 tempname2 = make_temp(f2, &stb2);
317 if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size) { 323 if (stb1.st_size != stb2.st_size) {
318 return 1; 324 return 1;
319 } 325 }
320 while (1) { 326 while (1) {
@@ -631,8 +637,8 @@ static NOINLINE void check(FILE *f1, FILE *f2)
631 J[i] = 0; 637 J[i] = 0;
632 if (c != '\n' && c != EOF) 638 if (c != '\n' && c != EOF)
633 ctold += skipline(f1); 639 ctold += skipline(f1);
634// BUG? Should be "if (d != '\n' && d != EOF)" ? 640/* was buggy? "if (d != '\n' && c != EOF)" */
635 if (d != '\n' && c != EOF) 641 if (d != '\n' && d != EOF)
636 ctnew += skipline(f2); 642 ctnew += skipline(f2);
637 break; 643 break;
638 } 644 }