version 1.14, 2003/06/26 07:20:12 |
version 1.15, 2003/06/26 18:19:29 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
* POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#include <errno.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
#include <stdarg.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "diff.h" |
#include "diff.h" |
|
|
const char *diffh = _PATH_DIFFH; |
const char *diffh = _PATH_DIFFH; |
const char *pr = _PATH_PR; |
const char *pr = _PATH_PR; |
|
|
static void noroom(void); |
|
__dead void usage(void); |
__dead void usage(void); |
|
|
int |
int |
|
|
argv += optind; |
argv += optind; |
|
|
if (argc != 2) |
if (argc != 2) |
errx(1, "two filename arguments required"); |
errorx("two filename arguments required"); |
file1 = argv[0]; |
file1 = argv[0]; |
file2 = argv[1]; |
file2 = argv[1]; |
if (hflag && opt) |
if (hflag && opt) |
errx(1, "-h doesn't support -D, -c, -C, -e, -f, -I, -n, -u or -U"); |
errorx("-h doesn't support -D, -c, -C, -e, -f, -I, -n, -u or -U"); |
if (!strcmp(file1, "-")) |
if (!strcmp(file1, "-")) |
stb1.st_mode = S_IFREG; |
stb1.st_mode = S_IFREG; |
else if (stat(file1, &stb1) < 0) |
else if (stat(file1, &stb1) < 0) |
err(1, "%s", file1); |
error("%s", file1); |
if (!strcmp(file2, "-")) |
if (!strcmp(file2, "-")) |
stb2.st_mode = S_IFREG; |
stb2.st_mode = S_IFREG; |
else if (stat(file2, &stb2) < 0) |
else if (stat(file2, &stb2) < 0) |
err(1, "%s", file2); |
error("%s", file2); |
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) |
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) |
diffdir(argv); |
diffdir(argv); |
else |
else |
|
|
__dead void |
__dead void |
done(int sig) |
done(int sig) |
{ |
{ |
if (tempfiles[0]) |
if (tempfiles[0] != NULL) |
unlink(tempfiles[0]); |
unlink(tempfiles[0]); |
if (tempfiles[1]) |
if (tempfiles[1] != NULL) |
unlink(tempfiles[1]); |
unlink(tempfiles[1]); |
if (sig) |
if (sig) |
_exit(status); |
_exit(status); |
|
|
void *p; |
void *p; |
|
|
if ((p = malloc(n)) == NULL) |
if ((p = malloc(n)) == NULL) |
noroom(); |
error("files too big, try -h"); |
return (p); |
return (p); |
} |
} |
|
|
|
|
void *q; |
void *q; |
|
|
if ((q = realloc(p, n)) == NULL) |
if ((q = realloc(p, n)) == NULL) |
noroom(); |
error("files too big, try -h"); |
return (q); |
return (q); |
} |
} |
|
|
static void |
__dead void |
noroom(void) |
error(const char *fmt, ...) |
{ |
{ |
warn("files too big, try -h"); |
va_list ap; |
done(0); |
int sverrno = errno; |
|
|
|
if (tempfiles[0] != NULL) |
|
unlink(tempfiles[0]); |
|
if (tempfiles[1] != NULL) |
|
unlink(tempfiles[1]); |
|
errno = sverrno; |
|
va_start(ap, fmt); |
|
verr(status, fmt, ap); |
|
va_end(ap); |
} |
} |
|
|
__dead void |
__dead void |
|
errorx(const char *fmt, ...) |
|
{ |
|
va_list ap; |
|
|
|
if (tempfiles[0] != NULL) |
|
unlink(tempfiles[0]); |
|
if (tempfiles[1] != NULL) |
|
unlink(tempfiles[1]); |
|
va_start(ap, fmt); |
|
verrx(status, fmt, ap); |
|
va_end(ap); |
|
} |
|
|
|
__dead void |
usage(void) |
usage(void) |
{ |
{ |
(void)fprintf(stderr, |
(void)fprintf(stderr, |
|
|
" diff [-biwt] [-c | -e | -f | -h | -n | -u ] " |
" diff [-biwt] [-c | -e | -f | -h | -n | -u ] " |
"[-l] [-r] [-s] [-S name]\n dir1 dir2\n"); |
"[-l] [-r] [-s] [-S name]\n dir1 dir2\n"); |
|
|
exit(1); |
exit(2); |
} |
} |