aboutsummaryrefslogtreecommitdiff
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
parent7fe0ebac5f22a810ee25ea182582ee71d6bf86b2 (diff)
downloadbusybox-e9d67a81c8c8ca0d256670929353b9a8d3b18563.tar.gz
diff: fix small bug; don't make a copy for "/dev/null" case
-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)
char *name;
int fd;
- if (S_ISREG(sb->st_mode))
+ if (S_ISREG(sb->st_mode) || S_ISBLK(sb->st_mode))
return NULL;
name = xstrdup("/tmp/difXXXXXX");
fd = mkstemp(name);
@@ -312,9 +312,15 @@ static NOINLINE int files_differ(FILE *f1, FILE *f2, int flags)
{
size_t i, j;
+ /* Prevent making copies for "/dev/null" (too common) */
+ tempname1 = tempname2 = NULL;
+ if (flags & (D_EMPTY1 | D_EMPTY2)) {
+ return 1;
+ }
+ /* Deal with input from pipes etc */
tempname1 = make_temp(f1, &stb1);
tempname2 = make_temp(f2, &stb2);
- if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size) {
+ if (stb1.st_size != stb2.st_size) {
return 1;
}
while (1) {
@@ -631,8 +637,8 @@ static NOINLINE void check(FILE *f1, FILE *f2)
J[i] = 0;
if (c != '\n' && c != EOF)
ctold += skipline(f1);
-// BUG? Should be "if (d != '\n' && d != EOF)" ?
- if (d != '\n' && c != EOF)
+/* was buggy? "if (d != '\n' && c != EOF)" */
+ if (d != '\n' && d != EOF)
ctnew += skipline(f2);
break;
}