version 1.27, 2003/07/09 00:07:44 |
version 1.28, 2003/07/09 00:39:25 |
|
|
#include <err.h> |
#include <err.h> |
#include <errno.h> |
#include <errno.h> |
#include <getopt.h> |
#include <getopt.h> |
|
#include <signal.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdarg.h> |
|
|
break; |
break; |
case 'l': |
case 'l': |
lflag = 1; |
lflag = 1; |
|
signal(SIGPIPE, SIG_IGN); |
break; |
break; |
case 'N': |
case 'N': |
Nflag = 1; |
Nflag = 1; |
|
|
fstat(STDIN_FILENO, &stb1); |
fstat(STDIN_FILENO, &stb1); |
gotstdin = 1; |
gotstdin = 1; |
} else if (stat(argv[0], &stb1) != 0) |
} else if (stat(argv[0], &stb1) != 0) |
error("%s", argv[0]); |
err(2, "%s", argv[0]); |
if (strcmp(argv[1], "-") == 0) { |
if (strcmp(argv[1], "-") == 0) { |
fstat(STDIN_FILENO, &stb2); |
fstat(STDIN_FILENO, &stb2); |
gotstdin = 1; |
gotstdin = 1; |
} else if (stat(argv[1], &stb2) != 0) |
} else if (stat(argv[1], &stb2) != 0) |
error("%s", argv[1]); |
err(2, "%s", argv[1]); |
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) |
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) |
errorx("can't compare - to a directory"); |
errx(2, "can't compare - to a directory"); |
set_argstr(oargv, argv); |
set_argstr(oargv, argv); |
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
if (format == D_IFDEF) |
if (format == D_IFDEF) |
errorx("-D option not supported with directories"); |
errx(2, "-D option not supported with directories"); |
diffdir(argv[0], argv[1]); |
diffdir(argv[0], argv[1]); |
} else { |
} else { |
|
if (S_ISDIR(stb1.st_mode)) { |
|
argv[0] = splice(argv[0], argv[1]); |
|
if (stat(argv[0], &stb1) < 0) |
|
err(2, "%s", argv[0]); |
|
} |
|
if (S_ISDIR(stb2.st_mode)) { |
|
argv[1] = splice(argv[1], argv[0]); |
|
if (stat(argv[1], &stb2) < 0) |
|
err(2, "%s", argv[1]); |
|
} |
print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], |
print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], |
NULL); |
NULL); |
} |
} |
exit(status); |
exit(status); |
} |
} |
|
|
void |
|
quit(int signo) |
|
{ |
|
if (tempfiles[0] != NULL) |
|
unlink(tempfiles[0]); |
|
if (tempfiles[1] != NULL) |
|
unlink(tempfiles[1]); |
|
_exit(status); |
|
} |
|
|
|
void * |
void * |
emalloc(size_t n) |
emalloc(size_t n) |
{ |
{ |
void *p; |
void *p; |
|
|
if ((p = malloc(n)) == NULL) |
if ((p = malloc(n)) == NULL) |
error(NULL); |
err(2, NULL); |
return (p); |
return (p); |
} |
} |
|
|
|
|
void *q; |
void *q; |
|
|
if ((q = realloc(p, n)) == NULL) |
if ((q = realloc(p, n)) == NULL) |
error(NULL); |
err(2, NULL); |
return (q); |
return (q); |
} |
} |
|
|
|
|
va_end(ap); |
va_end(ap); |
|
|
if (len == -1) |
if (len == -1) |
error(NULL); |
err(2, NULL); |
return(len); |
return(len); |
} |
} |
|
|
__dead void |
|
error(const char *fmt, ...) |
|
{ |
|
va_list ap; |
|
int sverrno = errno; |
|
|
|
if (tempfiles[0] != NULL) |
|
unlink(tempfiles[0]); |
|
if (tempfiles[1] != NULL) |
|
unlink(tempfiles[1]); |
|
errno = sverrno; |
|
va_start(ap, fmt); |
|
verr(2, fmt, ap); |
|
va_end(ap); |
|
} |
|
|
|
__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(2, fmt, ap); |
|
va_end(ap); |
|
} |
|
|
|
void |
void |
set_argstr(char **av, char **ave) |
set_argstr(char **av, char **ave) |
{ |
{ |
|
|
if (strcmp(file, "-") == 0) |
if (strcmp(file, "-") == 0) |
fp = stdin; |
fp = stdin; |
else if ((fp = fopen(file, "r")) == NULL) |
else if ((fp = fopen(file, "r")) == NULL) |
error("%s", file); |
err(2, "%s", file); |
while ((buf = fgetln(fp, &len)) != NULL) { |
while ((buf = fgetln(fp, &len)) != NULL) { |
if (buf[len - 1] == '\n') |
if (buf[len - 1] == '\n') |
len--; |
len--; |
|
|
printf("Files %s%s and %s%s are identical\n", |
printf("Files %s%s and %s%s are identical\n", |
path1, entry ? entry : "", |
path1, entry ? entry : "", |
path2, entry ? entry : ""); |
path2, entry ? entry : ""); |
|
break; |
|
case D_MISMATCH: |
|
printf("File %s/%s is a directory but file %s/%s is not\n", |
|
path1, entry ? entry : "", path2, entry ? entry : ""); |
break; |
break; |
} |
} |
} |
} |