diff options
author | 2003-06-25 17:49:22 +0000 | |
---|---|---|
committer | 2003-06-25 17:49:22 +0000 | |
commit | c42aed393163dc59fed20be357abb1e4a21a3996 (patch) | |
tree | b5c6d502b58327a06e7c43abea02046911f581a6 /usr.bin/diff/diffreg.c | |
parent | Recent bus_space changes make ne at pcmcia work out of the box, (diff) | |
download | wireguard-openbsd-c42aed393163dc59fed20be357abb1e4a21a3996.tar.xz wireguard-openbsd-c42aed393163dc59fed20be357abb1e4a21a3996.zip |
o use getopt()
o use err/warn
o only call done() when needed (after mkstemp)
o add "-C lines" like GNU grep
OK deraadt@
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r-- | usr.bin/diff/diffreg.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 332033afead..195002401b3 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.14 2003/06/25 07:26:59 tedu Exp $ */ +/* $OpenBSD: diffreg.c,v 1.15 2003/06/25 17:49:22 millert Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -231,52 +231,45 @@ diffreg(void) if (hflag) { diffargv[0] = "diffh"; execv(diffh, diffargv); - fprintf(stderr, "diff: "); - perror(diffh); + warn("%s", diffh); done(0); } chrtran = (iflag ? cup2low : clow2low); if ((stb1.st_mode & S_IFMT) == S_IFDIR) { file1 = splice(file1, file2); if (stat(file1, &stb1) < 0) { - fprintf(stderr, "diff: "); - perror(file1); + warn("%s", file1); 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); + warn("%s", file2); done(0); } } else if ((stb1.st_mode & S_IFMT) != S_IFREG || !strcmp(file1, "-")) { if (!strcmp(file2, "-")) { - fprintf(stderr, "diff: can't specify - -\n"); + warnx("can't specify - -"); done(0); } file1 = copytemp(); if (stat(file1, &stb1) < 0) { - fprintf(stderr, "diff: "); - perror(file1); + warn("%s", file1); 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); + warn("%s", file2); done(0); } } if ((f1 = fopen(file1, "r")) == NULL) { - fprintf(stderr, "diff: "); - perror(file1); + warn("%s", file1); done(0); } if ((f2 = fopen(file2, "r")) == NULL) { - fprintf(stderr, "diff: "); - perror(file2); + warn("%s", file2); fclose(f1); done(0); } @@ -360,14 +353,12 @@ copytemp(void) signal(SIGTERM, done); f = mkstemp(tempfile); if (f < 0) { - fprintf(stderr, "diff: "); - perror(tempfile); + warn("%s", tempfile); done(0); } while ((i = read(0, buf, BUFSIZ)) > 0) if (write(f, buf, i) != i) { - fprintf(stderr, "diff: "); - perror(tempfile); + warn("%s", tempfile); done(0); } close(f); @@ -380,7 +371,7 @@ splice(char *dir, char *file) char *tail, buf[BUFSIZ]; if (!strcmp(file, "-")) { - fprintf(stderr, "diff: can't specify - with other arg directory\n"); + warnx("can't specify - with other arg directory"); done(0); } tail = strrchr(file, '/'); |