summaryrefslogtreecommitdiff
path: root/usr.bin/diff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-03-16 00:40:35 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-03-16 00:40:35 +0000
commit5158e01d42b380c30ab5e2d29d8b053c2e336cb2 (patch)
treef872d2d0057bdfc57245bfda76f7280be81b324d /usr.bin/diff
parent170a06b52be749493e3b2375fe154d810b3aa5f1 (diff)
POSIX specifies that in directory mode device special files and
FIFOs shall be skipped. Other types of files may be skipped too (this is implementation-dependent). In directory mode, just skip anything that is not a regular file or directory. OK tedu@
Diffstat (limited to 'usr.bin/diff')
-rw-r--r--usr.bin/diff/diff.15
-rw-r--r--usr.bin/diff/diff.c12
-rw-r--r--usr.bin/diff/diff.h4
-rw-r--r--usr.bin/diff/diffdir.c11
4 files changed, 25 insertions, 7 deletions
diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1
index 48adb1307d2..633c2f435c0 100644
--- a/usr.bin/diff/diff.1
+++ b/usr.bin/diff/diff.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: diff.1,v 1.24 2004/01/25 14:48:32 jmc Exp $
+.\" $OpenBSD: diff.1,v 1.25 2004/03/16 00:40:34 millert Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -284,6 +284,9 @@ on text files which are different.
Binary files which differ,
common subdirectories, and files which appear in only one directory
are described as such.
+In directory mode only regular files and directories are compared.
+If a non-regular file such as a device special file or FIFO is
+encountered, a diagnostic message is printed.
.Pp
If only one of
.Ar file1
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c
index 7ad00106cae..134cb37c0f3 100644
--- a/usr.bin/diff/diff.c
+++ b/usr.bin/diff/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.44 2004/01/07 17:18:32 otto Exp $ */
+/* $OpenBSD: diff.c,v 1.45 2004/03/16 00:40:34 millert Exp $ */
/*
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -21,7 +21,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diff.c,v 1.44 2004/01/07 17:18:32 otto Exp $";
+static const char rcsid[] = "$OpenBSD: diff.c,v 1.45 2004/03/16 00:40:34 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -385,6 +385,14 @@ print_status(int val, char *path1, char *path2, char *entry)
printf("File %s%s is a regular file while file %s%s is a directory\n",
path1, entry ? entry : "", path2, entry ? entry : "");
break;
+ case D_SKIPPED1:
+ printf("File %s%s is not a regular file or directory and was skipped\n",
+ path1, entry ? entry : "");
+ break;
+ case D_SKIPPED2:
+ printf("File %s%s is not a regular file or directory and was skipped\n",
+ path2, entry ? entry : "");
+ break;
}
}
diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h
index 7f658699fa3..d9af1a94c0e 100644
--- a/usr.bin/diff/diff.h
+++ b/usr.bin/diff/diff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.h,v 1.26 2004/01/07 17:18:32 otto Exp $ */
+/* $OpenBSD: diff.h,v 1.27 2004/03/16 00:40:34 millert Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -62,6 +62,8 @@
#define D_MISMATCH1 5 /* path1 was a dir, path2 a file */
#define D_MISMATCH2 6 /* path1 was a file, path2 a dir */
#define D_ERROR 7 /* An error occurred */
+#define D_SKIPPED1 8 /* path1 was a special file */
+#define D_SKIPPED2 9 /* path2 was a special file */
struct excludes {
char *pattern;
diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c
index 3223c75770d..bf2b3f01ff5 100644
--- a/usr.bin/diff/diffdir.c
+++ b/usr.bin/diff/diffdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffdir.c,v 1.26 2003/11/09 20:13:57 otto Exp $ */
+/* $OpenBSD: diffdir.c,v 1.27 2004/03/16 00:40:34 millert Exp $ */
/*
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -21,7 +21,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.26 2003/11/09 20:13:57 otto Exp $";
+static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.27 2004/03/16 00:40:34 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -283,7 +283,12 @@ diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2)
path1, path2);
return;
}
- dp->d_status = diffreg(path1, path2, flags);
+ if (!S_ISREG(stb1.st_mode) && !S_ISDIR(stb1.st_mode))
+ dp->d_status = D_SKIPPED1;
+ else if (!S_ISREG(stb2.st_mode) && !S_ISDIR(stb2.st_mode))
+ dp->d_status = D_SKIPPED2;
+ else
+ dp->d_status = diffreg(path1, path2, flags);
if (!lflag)
print_status(dp->d_status, path1, path2, NULL);
}