summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/diff/diff.c26
-rw-r--r--usr.bin/diff/diff.h4
-rw-r--r--usr.bin/diff/diffdir.c16
-rw-r--r--usr.bin/diff/diffreg.c32
4 files changed, 40 insertions, 38 deletions
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c
index 4625f99a9e0..8eba550652c 100644
--- a/usr.bin/diff/diff.c
+++ b/usr.bin/diff/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.3 2003/06/25 03:02:33 tedu Exp $ */
+/* $OpenBSD: diff.c,v 1.4 2003/06/25 03:37:32 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -126,7 +126,7 @@ main(int argc, char **argv)
if (*argp) {
fprintf(stderr,
"diff: -c: bad count\n");
- done();
+ done(0);
}
argp = "";
} else
@@ -138,7 +138,7 @@ main(int argc, char **argv)
case 'S':
if (*argp == 0) {
fprintf(stderr, "diff: use -Sstart\n");
- done();
+ done(0);
}
start = argp;
*--argp = 0; /* don't pass it on */
@@ -155,40 +155,40 @@ main(int argc, char **argv)
default:
fprintf(stderr, "diff: -%s: unknown option\n",
--argp);
- done();
+ done(0);
}
}
if (argc != 2) {
fprintf(stderr, "diff: two filename arguments required\n");
- done();
+ done(0);
}
file1 = argv[0];
file2 = argv[1];
if (hflag && opt) {
fprintf(stderr,
"diff: -h doesn't support -e, -f, -n, -c, or -I\n");
- done();
+ done(0);
}
if (!strcmp(file1, "-"))
stb1.st_mode = S_IFREG;
else if (stat(file1, &stb1) < 0) {
fprintf(stderr, "diff: ");
perror(file1);
- done();
+ done(0);
}
if (!strcmp(file2, "-"))
stb2.st_mode = S_IFREG;
else if (stat(file2, &stb2) < 0) {
fprintf(stderr, "diff: ");
perror(file2);
- done();
+ done(0);
}
if ((stb1.st_mode & S_IFMT) == S_IFDIR &&
(stb2.st_mode & S_IFMT) == S_IFDIR) {
diffdir(argv);
} else
diffreg();
- done();
+ done(0);
/* notreached */
return (0);
}
@@ -208,10 +208,12 @@ max(int a, int b)
}
void
-done(void)
+done(int sig)
{
if (tempfile)
unlink(tempfile);
+ if (sig)
+ _exit(status);
exit(status);
}
@@ -219,7 +221,7 @@ void
catchsig(int sigraised)
{
/* print something? */
- done();
+ done(0);
}
void *
@@ -246,5 +248,5 @@ static void
noroom(void)
{
fprintf(stderr, "diff: files too big, try -h\n");
- done();
+ done(0);
}
diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h
index 0aafd79784f..642d8278b38 100644
--- a/usr.bin/diff/diff.h
+++ b/usr.bin/diff/diff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.h,v 1.3 2003/06/25 03:02:33 tedu Exp $ */
+/* $OpenBSD: diff.h,v 1.4 2003/06/25 03:37:32 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -118,7 +118,7 @@ void *ralloc(void *, size_t);
char *splice(char *, char *);
char *copytemp(void);
void catchsig(int);
-void done(void);
+void done(int);
void diffdir(char **);
void diffreg(void);
int max(int, int);
diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c
index 4e0b8da1e75..6e81615bf92 100644
--- a/usr.bin/diff/diffdir.c
+++ b/usr.bin/diff/diffdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffdir.c,v 1.6 2003/06/25 03:32:11 deraadt Exp $ */
+/* $OpenBSD: diffdir.c,v 1.7 2003/06/25 03:37:32 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -92,7 +92,7 @@ diffdir(char **argv)
if (opt == D_IFDEF) {
fprintf(stderr, "diff: can't specify -I with directories\n");
- done();
+ done(0);
}
if (opt == D_EDIT && (sflag || lflag))
fprintf(stderr,
@@ -232,7 +232,7 @@ setupdir(char *cp)
if (dirp == NULL) {
fprintf(stderr, "diff: ");
perror(cp);
- done();
+ done(0);
}
nitems = 0;
dp = talloc(sizeof(struct dir));
@@ -367,7 +367,7 @@ calldiff(char *wantpr)
pid = fork();
if (pid == -1) {
fprintf(stderr, "No more processes");
- done();
+ done(0);
}
if (pid == 0) {
close(0);
@@ -377,13 +377,13 @@ calldiff(char *wantpr)
execv(pr + 4, prargs);
execv(pr, prargs);
perror(pr);
- done();
+ done(0);
}
}
pid = fork();
if (pid == -1) {
fprintf(stderr, "diff: No more processes\n");
- done();
+ done(0);
}
if (pid == 0) {
if (wantpr) {
@@ -395,7 +395,7 @@ calldiff(char *wantpr)
execv(diff + 4, diffargv);
execv(diff, diffargv);
perror(diff);
- done();
+ done(0);
}
if (wantpr) {
close(pv[0]);
@@ -407,7 +407,7 @@ calldiff(char *wantpr)
continue;
/*
if ((lstatus >> 8) >= 2)
- done();
+ done(0);
*/
dirstatus |= lstatus >> 8;
}
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index e1e01601ccc..feede260423 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.4 2003/06/25 03:25:29 tedu Exp $ */
+/* $OpenBSD: diffreg.c,v 1.5 2003/06/25 03:37:32 deraadt Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -234,7 +234,7 @@ diffreg(void)
execv(diffh, diffargv);
fprintf(stderr, "diff: ");
perror(diffh);
- done();
+ done(0);
}
chrtran = (iflag ? cup2low : clow2low);
if ((stb1.st_mode & S_IFMT) == S_IFDIR) {
@@ -242,44 +242,44 @@ diffreg(void)
if (stat(file1, &stb1) < 0) {
fprintf(stderr, "diff: ");
perror(file1);
- done();
+ done(0);
}
} else if ((stb2.st_mode & S_IFMT) == S_IFDIR) {
file2 = splice(file2, file1);
if (stat(file2, &stb2) < 0) {
fprintf(stderr, "diff: ");
perror(file2);
- done();
+ done(0);
}
} else if ((stb1.st_mode & S_IFMT) != S_IFREG || !strcmp(file1, "-")) {
if (!strcmp(file2, "-")) {
fprintf(stderr, "diff: can't specify - -\n");
- done();
+ done(0);
}
file1 = copytemp();
if (stat(file1, &stb1) < 0) {
fprintf(stderr, "diff: ");
perror(file1);
- done();
+ done(0);
}
} else if ((stb2.st_mode & S_IFMT) != S_IFREG || !strcmp(file2, "-")) {
file2 = copytemp();
if (stat(file2, &stb2) < 0) {
fprintf(stderr, "diff: ");
perror(file2);
- done();
+ done(0);
}
}
if ((f1 = fopen(file1, "r")) == NULL) {
fprintf(stderr, "diff: ");
perror(file1);
- done();
+ done(0);
}
if ((f2 = fopen(file2, "r")) == NULL) {
fprintf(stderr, "diff: ");
perror(file2);
fclose(f1);
- done();
+ done(0);
}
if (stb1.st_size != stb2.st_size)
goto notsame;
@@ -307,7 +307,7 @@ notsame:
printf("Binary files %s and %s differ\n", file1, file2);
fclose(f1);
fclose(f2);
- done();
+ done(0);
}
prepare(0, f1);
prepare(1, f2);
@@ -344,7 +344,7 @@ notsame:
same:
if (opt == D_CONTEXT && anychange == 0)
printf("No differences encountered\n");
- done();
+ done(0);
}
char *tempfile = _PATH_TMP;
@@ -363,13 +363,13 @@ copytemp(void)
if (f < 0) {
fprintf(stderr, "diff: ");
perror(tempfile);
- done();
+ done(0);
}
while ((i = read(0, buf, BUFSIZ)) > 0)
if (write(f, buf, i) != i) {
fprintf(stderr, "diff: ");
perror(tempfile);
- done();
+ done(0);
}
close(f);
return (tempfile);
@@ -383,7 +383,7 @@ splice(char *dir, char *file)
if (!strcmp(file, "-")) {
fprintf(stderr, "diff: can't specify - with other arg directory\n");
- done();
+ done(0);
}
tail = rindex(file, '/');
if (tail == 0)
@@ -560,11 +560,11 @@ check(void)
if ((input[0] = fopen(file1, "r")) == NULL) {
perror(file1);
- done();
+ done(0);
}
if ((input[1] = fopen(file2, "r")) == NULL) {
perror(file2);
- done();
+ done(0);
}
j = 1;
ixold[0] = ixnew[0] = 0;