aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:55:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-24 16:55:13 +0000
commitc4c2cd44d2befc5c1153cd54e1ceb93b88fee243 (patch)
treed41fcfd0fd5b4f660ca26f3342cf31612639e422
parente9d67a81c8c8ca0d256670929353b9a8d3b18563 (diff)
downloadbusybox-w32-c4c2cd44d2befc5c1153cd54e1ceb93b88fee243.tar.gz
busybox-w32-c4c2cd44d2befc5c1153cd54e1ceb93b88fee243.tar.bz2
busybox-w32-c4c2cd44d2befc5c1153cd54e1ceb93b88fee243.zip
diff: exclude D_EMPTY code if there is no support for -r
function old new delta diffreg 1808 1825 +17 files_differ 189 166 -23
-rw-r--r--editors/diff.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 27c8365cc..08729177c 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -22,9 +22,13 @@
22/* 22/*
23 * Output flags 23 * Output flags
24 */ 24 */
25#define D_HEADER 1 /* Print a header/footer between files */ 25enum {
26#define D_EMPTY1 2 /* Treat first file as empty (/dev/null) */ 26 /* Print a header/footer between files */
27#define D_EMPTY2 4 /* Treat second file as empty (/dev/null) */ 27 /* D_HEADER = 1, - unused */
28 /* Treat file as empty (/dev/null) */
29 D_EMPTY1 = 2 * ENABLE_FEATURE_DIFF_DIR,
30 D_EMPTY2 = 4 * ENABLE_FEATURE_DIFF_DIR,
31};
28 32
29/* 33/*
30 * Status values for print_status() and diffreg() return values 34 * Status values for print_status() and diffreg() return values
@@ -308,15 +312,11 @@ static char *make_temp(FILE *f, struct stat *sb)
308 * Check to see if the given files differ. 312 * Check to see if the given files differ.
309 * Returns 0 if they are the same, 1 if different, and -1 on error. 313 * Returns 0 if they are the same, 1 if different, and -1 on error.
310 */ 314 */
311static NOINLINE int files_differ(FILE *f1, FILE *f2, int flags) 315static NOINLINE int files_differ(FILE *f1, FILE *f2)
312{ 316{
313 size_t i, j; 317 size_t i, j;
314 318
315 /* Prevent making copies for "/dev/null" (too common) */ 319 /* 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 */ 320 /* Deal with input from pipes etc */
321 tempname1 = make_temp(f1, &stb1); 321 tempname1 = make_temp(f1, &stb1);
322 tempname2 = make_temp(f2, &stb2); 322 tempname2 = make_temp(f2, &stb2);
@@ -1008,6 +1008,7 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1008 1008
1009 anychange = 0; 1009 anychange = 0;
1010 context_vec_ptr = context_vec_start - 1; 1010 context_vec_ptr = context_vec_start - 1;
1011 tempname1 = tempname2 = NULL;
1011 1012
1012 /* Is any of them a directory? Then it's simple */ 1013 /* Is any of them a directory? Then it's simple */
1013 if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) 1014 if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
@@ -1025,13 +1026,18 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1025 else 1026 else
1026 f2 = xfopen_stdin(file2); 1027 f2 = xfopen_stdin(file2);
1027 1028
1028 /* Quick check whether they are different */ 1029 /* NB: if D_EMPTY1/2 is set, other file is always a regular file,
1029 /* NB: copies non-REG files to tempfiles and fills tempname1/2 */ 1030 * not pipe/fifo/chardev/etc - D_EMPTY is used by "diff -r" only,
1030 i = files_differ(f1, f2, flags); 1031 * and it never diffs non-ordinary files in subdirs. */
1031 if (i != 1) { /* not different? */ 1032 if (!(flags & (D_EMPTY1 | D_EMPTY2))) {
1032 if (i != 0) /* error? */ 1033 /* Quick check whether they are different */
1033 exit_status |= 2; 1034 /* NB: copies non-REG files to tempfiles and fills tempname1/2 */
1034 goto closem; 1035 i = files_differ(f1, f2);
1036 if (i != 1) { /* not different? */
1037 if (i != 0) /* error? */
1038 exit_status |= 2;
1039 goto closem;
1040 }
1035 } 1041 }
1036 1042
1037 if (!asciifile(f1) || !asciifile(f2)) { 1043 if (!asciifile(f1) || !asciifile(f2)) {
@@ -1098,7 +1104,7 @@ static unsigned diffreg(char *file1, char *file2, int flags)
1098#if ENABLE_FEATURE_DIFF_DIR 1104#if ENABLE_FEATURE_DIFF_DIR
1099static void do_diff(char *dir1, char *path1, char *dir2, char *path2) 1105static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
1100{ 1106{
1101 int flags = D_HEADER; 1107 int flags = 0; /*D_HEADER;*/
1102 int val; 1108 int val;
1103 char *fullpath1 = NULL; /* if -N */ 1109 char *fullpath1 = NULL; /* if -N */
1104 char *fullpath2 = NULL; 1110 char *fullpath2 = NULL;