Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs.4bsd Subject: "diff" gets confused if one argument is a directory Message-ID: <2468@sun.uucp> Date: Sun, 21-Jul-85 20:27:45 EDT Article-I.D.: sun.2468 Posted: Sun Jul 21 20:27:45 1985 Date-Received: Wed, 24-Jul-85 20:00:39 EDT Distribution: net Organization: Sun Microsystems, Inc. Lines: 133 Index: bin/diff/diffreg.c 4.2BSD (probably also 4.3BSD) Description: If you do a "diff" where one file is a binary file, and the other file is a directory, it will probably report the files as different even if the file in the directory in question being compared with the other file is identical to it. Repeat-By: mkdir /tmp/x cp /tmp/x cd /tmp/x diff . Fix: Have "diff" redo the "stat" on the file in the directory in question, so that when it compares the sizes of the two files, it compares the sizes of the files rather than the size of the file and the size of the containing directory. Here's a "diff -c" listing - your line numbers may differ: *** diffreg.c.orig Mon Jun 3 21:59:38 1985 --- diffreg.c Sun Jul 21 17:24:25 1985 *************** *** 111,117 done(); } dummy = malloc(1); ! if ((stb1.st_mode & S_IFMT) == S_IFDIR) file1 = splice(file1, file2); else if ((stb2.st_mode & S_IFMT) == S_IFDIR) file2 = splice(file2, file1); --- 111,117 ----- done(); } dummy = malloc(1); ! if ((stb1.st_mode & S_IFMT) == S_IFDIR) { file1 = splice(file1, file2); if (stat(file1, &stb1) < 0) { fprintf(stderr, "diff: "); *************** *** 113,119 dummy = malloc(1); if ((stb1.st_mode & S_IFMT) == S_IFDIR) file1 = splice(file1, file2); ! else if ((stb2.st_mode & S_IFMT) == S_IFDIR) file2 = splice(file2, file1); else if (!strcmp(file1, "-")) { if (!strcmp(file2, "-")) { --- 113,124 ----- dummy = malloc(1); if ((stb1.st_mode & S_IFMT) == S_IFDIR) { file1 = splice(file1, file2); ! if (stat(file1, &stb1) < 0) { ! fprintf(stderr, "diff: "); ! perror(file1); ! done(); ! } ! } else if ((stb2.st_mode & S_IFMT) == S_IFDIR) { file2 = splice(file2, file1); if (stat(file2, &stb2) < 0) { fprintf(stderr, "diff: "); *************** *** 115,121 file1 = splice(file1, file2); else if ((stb2.st_mode & S_IFMT) == S_IFDIR) file2 = splice(file2, file1); ! else if (!strcmp(file1, "-")) { if (!strcmp(file2, "-")) { fprintf(stderr, "diff: can't specify - -\n"); done(); --- 120,131 ----- } } else if ((stb2.st_mode & S_IFMT) == S_IFDIR) { file2 = splice(file2, file1); ! if (stat(file2, &stb2) < 0) { ! fprintf(stderr, "diff: "); ! perror(file2); ! done(); ! } ! } else if (!strcmp(file1, "-")) { if (!strcmp(file2, "-")) { fprintf(stderr, "diff: can't specify - -\n"); done(); *************** *** 121,127 done(); } file1 = copytemp(); ! } else if (!strcmp(file2, "-")) file2 = copytemp(); if ((f1 = fopen(file1, "r")) == NULL) { fprintf(stderr, "diff: "); --- 131,142 ----- done(); } file1 = copytemp(); ! if (stat(file1, &stb1) < 0) { ! fprintf(stderr, "diff: "); ! perror(file1); ! done(); ! } ! } else if (!strcmp(file2, "-")) { file2 = copytemp(); if (stat(file2, &stb2) < 0) { fprintf(stderr, "diff: "); *************** *** 123,128 file1 = copytemp(); } else if (!strcmp(file2, "-")) file2 = copytemp(); if ((f1 = fopen(file1, "r")) == NULL) { fprintf(stderr, "diff: "); perror(file1); --- 138,149 ----- } } else if (!strcmp(file2, "-")) { file2 = copytemp(); + if (stat(file2, &stb2) < 0) { + fprintf(stderr, "diff: "); + perror(file2); + done(); + } + } if ((f1 = fopen(file1, "r")) == NULL) { fprintf(stderr, "diff: "); perror(file1);