Module Name: othersrc
Committed By: agc
Date: Wed Jan 16 01:50:20 UTC 2013
Modified Files:
othersrc/external/bsd/netdiff/dist: cmp.c diff.c diff_subr.c diffdir.c
diffreg.c mem.c netdiff.h netwdiff.c qdiff.c
Log Message:
Perform error message reporting differently, using an error buffer in
the diff_t structure.
Don't violate abstractions by accessing the status field in the
structure directly, use an accessor function to get the exit status
from the struct.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/netdiff/dist/cmp.c \
othersrc/external/bsd/netdiff/dist/diffdir.c \
othersrc/external/bsd/netdiff/dist/qdiff.c
cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/netdiff/dist/diff.c
cvs rdiff -u -r1.7 -r1.8 othersrc/external/bsd/netdiff/dist/diff_subr.c
cvs rdiff -u -r1.10 -r1.11 othersrc/external/bsd/netdiff/dist/diffreg.c
cvs rdiff -u -r1.1 -r1.2 othersrc/external/bsd/netdiff/dist/mem.c
cvs rdiff -u -r1.5 -r1.6 othersrc/external/bsd/netdiff/dist/netdiff.h
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/netdiff/dist/netwdiff.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/netdiff/dist/cmp.c
diff -u othersrc/external/bsd/netdiff/dist/cmp.c:1.2 othersrc/external/bsd/netdiff/dist/cmp.c:1.3
--- othersrc/external/bsd/netdiff/dist/cmp.c:1.2 Tue Jan 15 01:57:56 2013
+++ othersrc/external/bsd/netdiff/dist/cmp.c Wed Jan 16 01:50:19 2013
@@ -55,5 +55,5 @@ main(int argc, char **argv)
if (diff_get_diffs(&diff, &s, &cc)) {
printf("%.*s", (int)cc, s);
}
- exit(diff.status);
+ exit(diff_get_var(&diff, "(int)status", NULL, 0));
}
Index: othersrc/external/bsd/netdiff/dist/diffdir.c
diff -u othersrc/external/bsd/netdiff/dist/diffdir.c:1.2 othersrc/external/bsd/netdiff/dist/diffdir.c:1.3
--- othersrc/external/bsd/netdiff/dist/diffdir.c:1.2 Fri Jan 11 05:19:46 2013
+++ othersrc/external/bsd/netdiff/dist/diffdir.c Wed Jan 16 01:50:19 2013
@@ -59,7 +59,6 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <dirent.h>
-#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
@@ -133,7 +132,7 @@ slurpdir(diff_t *diff, char *path, size_
USE_ARG(enoentok);
if ((dirp = opendir(path)) == NULL) {
- warn("can't open directory '%s'", path);
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "can't open directory '%s' (%s)", path, strerror(errno));
return NULL;
}
dv = NULL;
@@ -165,7 +164,7 @@ diffit(diff_t *diff, struct dirent *dp,
strlcpy(path1 + plen1, dp->d_name, MAXPATHLEN - plen1);
if (stat(path1, &diff->st[0]) != 0) {
if (!(DIFF_GET_FLAG(diff, 'N') || DIFF_GET_FLAG(diff, 'P')) || errno != ENOENT) {
- warn("%s", path1);
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "%s (%s)", path1, strerror(errno));
return 0;
}
flags |= D_EMPTY1;
@@ -175,7 +174,7 @@ diffit(diff_t *diff, struct dirent *dp,
strlcpy(path2 + plen2, dp->d_name, MAXPATHLEN - plen2);
if (stat(path2, &diff->st[1]) != 0) {
if (!DIFF_GET_FLAG(diff, 'N') || errno != ENOENT) {
- warn("%s", path2);
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "%s (%s)", path2, strerror(errno));
return 0;
}
flags |= D_EMPTY2;
@@ -239,7 +238,7 @@ diff_dir(diff_t *diff, char *p1, char *p
}
dirlen1 = strlcpy(path1, *p1 ? p1 : ".", sizeof(path1));
if (dirlen1 >= sizeof(path1) - 1) {
- warnx("%s: %s", p1, strerror(ENAMETOOLONG));
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "%s: %s", p1, strerror(ENAMETOOLONG));
diff->status = 2;
return 0;
}
@@ -249,7 +248,7 @@ diff_dir(diff_t *diff, char *p1, char *p
}
dirlen2 = strlcpy(path2, *p2 ? p2 : ".", sizeof(path2));
if (dirlen2 >= sizeof(path2) - 1) {
- warnx("%s: %s", p2, strerror(ENAMETOOLONG));
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "%s: %s", p2, strerror(ENAMETOOLONG));
diff->status = 2;
return 0;
}
Index: othersrc/external/bsd/netdiff/dist/qdiff.c
diff -u othersrc/external/bsd/netdiff/dist/qdiff.c:1.2 othersrc/external/bsd/netdiff/dist/qdiff.c:1.3
--- othersrc/external/bsd/netdiff/dist/qdiff.c:1.2 Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/qdiff.c Wed Jan 16 01:50:20 2013
@@ -526,5 +526,5 @@ main(int argc, char **argv)
fprintf(stdout, "%.*s", (int)cc, s);
}
diff_fini(&diff);
- exit(diff.status);
+ exit(diff_get_var(&diff, "(int)status", NULL, 0));
}
Index: othersrc/external/bsd/netdiff/dist/diff.c
diff -u othersrc/external/bsd/netdiff/dist/diff.c:1.4 othersrc/external/bsd/netdiff/dist/diff.c:1.5
--- othersrc/external/bsd/netdiff/dist/diff.c:1.4 Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/dist/diff.c Wed Jan 16 01:50:19 2013
@@ -528,5 +528,5 @@ main(int argc, char **argv)
set_argstr(&diff, oargv, argv);
difference(&diff, argv[0], argv[1]);
diff_fini(&diff);
- exit(diff.status);
+ exit(diff_get_var(&diff, "(int)status", NULL, 0));
}
Index: othersrc/external/bsd/netdiff/dist/diff_subr.c
diff -u othersrc/external/bsd/netdiff/dist/diff_subr.c:1.7 othersrc/external/bsd/netdiff/dist/diff_subr.c:1.8
--- othersrc/external/bsd/netdiff/dist/diff_subr.c:1.7 Tue Jan 15 01:57:56 2013
+++ othersrc/external/bsd/netdiff/dist/diff_subr.c Wed Jan 16 01:50:19 2013
@@ -26,7 +26,6 @@
#include <sys/param.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <limits.h>
@@ -83,7 +82,9 @@ diff_printf(diff_t *diff, const char *fm
newv = realloc(diff->out, newsize);
if (newv == NULL) {
/* can't happen, right? :-( */
- warn("out of memory");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_printf: can't realloc %zu (%s)",
+ newsize, strerror(errno));
return -1;
}
diff->out = newv;
@@ -117,7 +118,9 @@ diff_write(diff_t *diff, const void *p,
newv = realloc(diff->out, newsize);
if (newv == NULL) {
/* can't happen, right? :-( */
- warn("out of memory");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_write: can't realloc %zu (%s)",
+ newsize, strerror(errno));
return 0;
}
diff->out = newv;
@@ -239,14 +242,20 @@ diff_get_diffs(diff_t *diff, char **ptr,
int
diff_get_var(diff_t *diff, const char *key, char *buf, size_t size)
{
- if (diff == NULL || key == NULL || buf == NULL) {
+ if (diff == NULL || key == NULL) {
return 0;
}
if (strcasecmp(key, "outc") == 0) {
- return snprintf(buf, size, "%zu", diff->outc);
+ return (buf == NULL) ? 0 : snprintf(buf, size, "%zu", diff->outc);
}
if (strcasecmp(key, "status") == 0) {
- return snprintf(buf, size, "%" PRIu32, diff->status);
+ return (buf == NULL) ? 0 : snprintf(buf, size, "%" PRIu32, diff->status);
+ }
+ if (strcasecmp(key, "(int)status") == 0) {
+ return diff->status;
+ }
+ if (strcasecmp(key, "errbuf") == 0) {
+ return (buf == NULL) ? 0 : snprintf(buf, size, "%s", diff->errbuf);
}
return 1;
}
@@ -268,11 +277,15 @@ diff_set_var(diff_t *diff, const char *k
if (strcmp(value, "[dynamic]") == 0) {
diff->outsize = (uint32_t) MB(2);
if ((diff->out = calloc(1, diff->outsize)) == NULL) {
- warn("can't calloc %zu", diff->outsize);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_set_var: can't calloc %zu (%s)",
+ diff->outsize, strerror(errno));
return 0;
}
} else if ((diff->fp = fopen(value, "w")) == NULL) {
- warn("can't open '%s' for output", value);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_set_var: can't open '%s' (%s)",
+ value, strerror(errno));
return 0;
}
}
@@ -438,17 +451,17 @@ difference(diff_t *diff, char *file1, ch
int error;
if ((diff->ignore = calloc(1, sizeof(regex_t))) == NULL) {
- warnx("calloc %zu bytes", sizeof(regex_t));
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: can't calloc %zu bytes (%s)",
+ sizeof(regex_t), strerror(errno));
return 2;
}
if ((error = regcomp(diff->ignore, diff->ign,
REG_NEWLINE | REG_EXTENDED)) != 0) {
regerror(error, diff->ignore, buf, sizeof(buf));
- if (*diff->ign != '\0') {
- warnx("%s: %s", diff->ign, buf);
- } else {
- warnx("%s", buf);
- }
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: regexp %s:%s (%s)",
+ (*diff->ign) ? diff->ign : "", buf, strerror(errno));
return 2;
}
}
@@ -456,29 +469,34 @@ difference(diff_t *diff, char *file1, ch
fstat(STDIN_FILENO, &diff->st[0]);
gotstdin = 1;
} else if (stat(file1, &diff->st[0]) != 0) {
- warn("%s", file1);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: can't stat '%s' (%s)", file1, strerror(errno));
return 2;
}
if (strcmp(file2, "-") == 0) {
fstat(STDIN_FILENO, &diff->st[1]);
gotstdin = 1;
} else if (stat(file2, &diff->st[1]) != 0) {
- warn("%s", file2);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: can't stat '%s' (%s)", file2, strerror(errno));
return 2;
}
if (gotstdin && (S_ISDIR(diff->st[0].st_mode) || S_ISDIR(diff->st[1].st_mode))) {
- warnx("can't compare - to a directory");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "can't compare to a directory");
return 2;
}
if (S_ISDIR(diff->st[0].st_mode) && S_ISDIR(diff->st[1].st_mode)) {
if (diff->format == D_IFDEF) {
if (diff->ifdefname != NULL) {
- warnx("-D option not supported with directories");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "-D option not supported with directories");
return 2;
}
}
if (diff->format == D_LF) {
- warnx("--line-format option not supported with directories");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "--line-format option not supported with directories");
return 2;
}
diff_dir(diff, file1, file2);
@@ -486,20 +504,25 @@ difference(diff_t *diff, char *file1, ch
if (S_ISDIR(diff->st[0].st_mode)) {
file1 = splice(file1, file2);
if (stat(file1, &diff->st[0]) < 0) {
- warn("%s", file1);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: can't stat '%s' (%s)",
+ file1, strerror(errno));
return 2;
}
}
if (S_ISDIR(diff->st[1].st_mode)) {
file2 = splice(file2, file1);
if (stat(file2, &diff->st[1]) < 0) {
- warn("%s", file2);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "difference: can't stat '%s' (%s)",
+ file2, strerror(errno));
return 2;
}
}
/* Checks if --to-file or --from-file are specified */
if (diff->Toflag && diff->Fromflag) {
- warnx("--from-file and --to-file both specified.\n");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "--from-file and --to-file both specified.\n");
return 2;
}
if (diff->Toflag) {
Index: othersrc/external/bsd/netdiff/dist/diffreg.c
diff -u othersrc/external/bsd/netdiff/dist/diffreg.c:1.10 othersrc/external/bsd/netdiff/dist/diffreg.c:1.11
--- othersrc/external/bsd/netdiff/dist/diffreg.c:1.10 Tue Jan 15 15:54:52 2013
+++ othersrc/external/bsd/netdiff/dist/diffreg.c Wed Jan 16 01:50:19 2013
@@ -102,7 +102,6 @@ __FBSDID("$FreeBSD$");
#include <sys/mman.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
@@ -514,14 +513,15 @@ readhash(diff_t *diff, file_t *f)
/* expand an array */
static int
-stretch(void **p, size_t *size, size_t elsize, size_t incr)
+stretch(diff_t *diff, void **p, size_t *size, size_t elsize, size_t incr)
{
size_t newsize;
void *newp;
newsize = *size + incr;
if ((newp = realloc(*p, newsize * elsize)) == NULL) {
- warn("can't realloc %zu bytes", newsize * elsize);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "stretch: can't realloc %zu bytes (%s)", newsize * elsize, strerror(errno));
return 0;
}
*p = newp;
@@ -548,7 +548,7 @@ prepare(diff_t *diff, file_t *f, off_t f
}
for (j = 0; (h = readhash(diff, f)) != 0 ; ) {
if (j == sz) {
- if (!stretch((void **)&p, &sz, sizeof(*p), sz / 2)) {
+ if (!stretch(diff, (void **)&p, &sz, sizeof(*p), sz / 2)) {
return 0;
}
}
@@ -630,12 +630,12 @@ isqrt(int n)
}
static int
-newcand(stone_t *s, int x, int y, int pred, int *found)
+newcand(diff_t *diff, stone_t *s, int x, int y, int pred, int *found)
{
candidate_t *q;
if (s->candc == s->candlistlen) {
- if (!stretch((void **)&s->candlist, &s->candlistlen, sizeof(*s->candlist), s->candlistlen / 10)) {
+ if (!stretch(diff, (void **)&s->candlist, &s->candlistlen, sizeof(*s->candlist), s->candlistlen / 10)) {
return 0;
}
}
@@ -687,7 +687,7 @@ stone(diff_t *diff, stone_t *s, int n)
const unsigned bound = (DIFF_GET_FLAG(diff, 'd')) ? UINT_MAX : (unsigned)MAX(256, isqrt(n));
k = 0;
- newcand(s, 0, 0, 0, &s->klist[0]);
+ newcand(diff, s, 0, 0, 0, &s->klist[0]);
for (i = 1; i <= n; i++) {
if ((j = s->class[i]) == 0) {
continue;
@@ -709,12 +709,12 @@ stone(diff_t *diff, stone_t *s, int n)
continue;
}
tc = s->klist[l];
- newcand(s, i, y, oldc, &s->klist[l]);
+ newcand(diff, s, i, y, oldc, &s->klist[l]);
oldc = tc;
oldl = l;
numtries++;
} else {
- newcand(s, i, y, oldc, &s->klist[l]);
+ newcand(diff, s, i, y, oldc, &s->klist[l]);
k++;
break;
}
@@ -987,17 +987,19 @@ unsort(diffline_t *f, int l, int *b)
}
static char *
-preadline(int fd, size_t size, off_t off)
+preadline(diff_t *diff, int fd, size_t size, off_t off)
{
ssize_t nr;
char *line;
if ((line = calloc(1, size + 1)) == NULL) {
- warn("preadline: calloc %zu", size + 1);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "preadline: can't calloc %zu (%s)", size + 1, strerror(errno));
return NULL;
}
if ((nr = pread(fd, line, size, off)) < 0) {
- warn("preadline: pread");
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "preadline: can't pread (%s)", strerror(errno));
return NULL;
}
if (nr > 0 && line[nr-1] == '\n') {
@@ -1195,7 +1197,7 @@ fetch(diff_t *diff, stone_t *s, file_t *
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
if ((c = diff_getc(diff, f)) == EOF) {
if (WARN_NO_NEWLINE(diff)) {
- warnx("No newline at end of file");
+ snprintf(diff->errbuf, sizeof(diff->errbuf), "No newline at end of file");
} else {
diff_printf(diff, "\n\\ No newline at end of file");
}
@@ -1407,7 +1409,7 @@ need_diff(diff_t *diff, file_t *f, int f
*/
if (from1 <= to1) { /* Changes and deletes. */
for (i = from1; i <= to1; i++) {
- line = preadline(fileno(f[0].fp),
+ line = preadline(diff, fileno(f[0].fp),
(size_t)(f[0].offsets[i] - f[0].offsets[i - 1]), f[0].offsets[i - 1]);
if (!ignoreline(diff, line)) {
return 1;
@@ -1416,7 +1418,7 @@ need_diff(diff_t *diff, file_t *f, int f
}
if (from1 > to1 || from2 <= to2) { /* Changes and inserts. */
for (i = from2; i <= to2; i++) {
- line = preadline(fileno(f[1].fp),
+ line = preadline(diff, fileno(f[1].fp),
(size_t)(f[1].offsets[i] - f[1].offsets[i - 1]), f[1].offsets[i - 1]);
if (!ignoreline(diff, line)) {
return 1;
@@ -1434,9 +1436,8 @@ show_context(diff_t *diff, stone_t *s, f
*/
if (s->context_vec_ptr == s->context_vec_end - 1) {
ptrdiff_t offset = s->context_vec_ptr - s->context_vec_start;
- if (!stretch((void **)&s->context_vec_start, &s->max_context,
+ if (!stretch(diff, (void **)&s->context_vec_start, &s->max_context,
sizeof(*s->context_vec_start), s->max_context)) {
- warn("change: realloc failure");
return 0;
}
s->context_vec_end = s->context_vec_start + s->max_context;
@@ -1801,27 +1802,31 @@ diffit(diff_t *diff, file_t *f, stone_t
s->member = (int *)(void *)f[1].file;
equiv(f[0].sfile, f[0].slen, f[1].sfile, f[1].slen, s->member);
sz = f[1].slen;
- if (!stretch((void **)&s->member, &sz, sizeof(*s->member), 2)) {
- warn("diff_file: realloc %zu bytes", sizeof(*s->member) * (sz + 2));
+ if (!stretch(diff, (void **)&s->member, &sz, sizeof(*s->member), 2)) {
return D_MISMATCH1;
}
s->class = (int *)(void *)f[0].file;
unsort(f[0].sfile, f[0].slen, s->class);
sz = f[0].slen;
- if (!stretch((void **)&s->class, &sz, sizeof(*s->class), 2)) {
- warn("diff_file: realloc %zu bytes", sizeof(*s->class) * (sz + 2));
+ if (!stretch(diff, (void **)&s->class, &sz, sizeof(*s->class), 2)) {
return D_MISMATCH1;
}
if ((s->klist = calloc(sizeof(*s->klist), f[0].slen + 2)) == NULL) {
- warn("diff_file: calloc %zu bytes", sizeof(*s->klist) * (f[0].slen + 2));
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_file: calloc %zu bytes (%s)",
+ sizeof(*s->klist) * (f[0].slen + 2),
+ strerror(errno));
return D_MISMATCH1;
}
s->candc = 0;
s->candlistlen = 100;
if ((s->candlist = calloc(s->candlistlen, sizeof(*s->candlist))) == NULL) {
- warn("diff_file: calloc %zu bytes", sizeof(*s->candlist) * s->candlistlen);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_file: calloc %zu bytes (%s)",
+ sizeof(*s->candlist) * s->candlistlen,
+ strerror(errno));
return D_MISMATCH1;
}
i = stone(diff, s, f[0].slen);
@@ -1829,8 +1834,7 @@ diffit(diff_t *diff, file_t *f, stone_t
free(s->class);
sz = f[0].len;
- if (!stretch((void **)&s->J, &sz, sizeof(*s->J), 2)) {
- warn("diff_file: realloc %zu bytes", sizeof(*s->J) * (sz + 2));
+ if (!stretch(diff, (void **)&s->J, &sz, sizeof(*s->J), 2)) {
return D_MISMATCH1;
}
unravel(s, f, s->klist[i]);
@@ -1838,13 +1842,11 @@ diffit(diff_t *diff, file_t *f, stone_t
free(s->klist);
sz = f[0].len;
- if (!stretch((void **)&f[0].offsets, &sz, sizeof(*f[0].offsets), 2)) {
- warn("diff_file: realloc %zu bytes", sizeof(*f[0].offsets) * (sz + 2));
+ if (!stretch(diff, (void **)&f[0].offsets, &sz, sizeof(*f[0].offsets), 2)) {
return D_MISMATCH1;
}
sz = f[1].len;
- if (!stretch((void **)&f[1].offsets, &sz, sizeof(*f[1].offsets), 2)) {
- warn("diff_file: realloc %zu bytes", sizeof(*f[1].offsets) * (sz + 2));
+ if (!stretch(diff, (void **)&f[1].offsets, &sz, sizeof(*f[1].offsets), 2)) {
return D_MISMATCH1;
}
check(diff, s, f);
@@ -1915,12 +1917,13 @@ typedef struct wordfile_t {
/* mmap the file */
static int
-mapfile(wordfile_t *f, const char *name)
+mapfile(diff_t *diff, wordfile_t *f, const char *name)
{
struct stat st;
if ((f->fp = fopen(name, "r")) == NULL) {
- warn("can't open '%s'", name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "mapfile: can't open '%s' (%s)", name, strerror(errno));
return 0;
}
f->name = strdup(name);
@@ -1928,7 +1931,8 @@ mapfile(wordfile_t *f, const char *name)
f->filesize = (size_t)st.st_size;
f->file = mmap(NULL, f->filesize, PROT_READ, MAP_SHARED, fileno(f->fp), 0);
if (f->file == MAP_FAILED) {
- warn("can't mmap '%s'", name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "mapfile: can't mmap '%s' (%s)", name, strerror(errno));
fclose(f->fp);
return 0;
}
@@ -1938,14 +1942,15 @@ mapfile(wordfile_t *f, const char *name)
/* split file into words */
static int
-splitfile(wordfile_t *f)
+splitfile(diff_t *diff, wordfile_t *f)
{
char *p;
int prevspace;
int inspace;
if ((f->splitwords = calloc(1, f->filesize)) == NULL) {
- warn("can't allocate '%s'", f->name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "splitfile: can't calloc %zu bytes (%s)", f->filesize, strerror(errno));
munmap(f->file, f->filesize);
fclose(f->fp);
return 0;
@@ -2161,12 +2166,14 @@ diff_file(diff_t *diff, const char *ofil
return D_MISMATCH1;
}
if ((f[0].fp = openfile(diff, f[0].name, 0, flags)) == NULL) {
- warn("%s", f[0].name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_file: can't open '%s' (%s)", f[0].name, strerror(errno));
diff->status |= 2;
return D_MISMATCH1;
}
if ((f[1].fp = openfile(diff, f[1].name, 1, flags)) == NULL) {
- warn("%s", f[1].name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "diff_file: can't open '%s' (%s)", f[1].name, strerror(errno));
diff->status |= 2;
return D_MISMATCH1;
}
@@ -2225,14 +2232,14 @@ wdiff_file(diff_t *diff, const char *f1,
local.inhibit = diff->inhibit;
diff_set_var(&local, "format", "normal");
diff_set_var(&local, "output", "[dynamic]");
- if (!mapfile(&wdf[0], f1)) {
+ if (!mapfile(diff, &wdf[0], f1)) {
return 0;
}
- splitfile(&wdf[0]);
- if (!mapfile(&wdf[1], f2)) {
+ splitfile(diff, &wdf[0]);
+ if (!mapfile(diff, &wdf[1], f2)) {
return 0;
}
- splitfile(&wdf[1]);
+ splitfile(diff, &wdf[1]);
diff_mem(&local, wdf[0].splitwords, wdf[0].splitwordscc, wdf[1].splitwords, wdf[1].splitwordscc, 0);
if (!diff_get_diffs(&local, &diffs, &cc)) {
return 0;
@@ -2267,8 +2274,8 @@ wdiff_mem(diff_t *diff, const char *m1,
wdf[0].filesize = size1;
wdf[1].file = __UNCONST(m2);
wdf[1].filesize = size2;
- splitfile(&wdf[0]);
- splitfile(&wdf[1]);
+ splitfile(diff, &wdf[0]);
+ splitfile(diff, &wdf[1]);
diff_mem(&local, wdf[0].splitwords, wdf[0].splitwordscc, wdf[1].splitwords, wdf[1].splitwordscc, 0);
if (!diff_get_diffs(&local, &diffs, &cc)) {
return 0;
@@ -2319,12 +2326,14 @@ cmp_file(diff_t *diff, const char *ofile
return D_MISMATCH1;
}
if ((f[0].fp = openfile(diff, f[0].name, 0, 0)) == NULL) {
- warn("%s", f[0].name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "cmp_file: can't open '%s' (%s)", f[0].name, strerror(errno));
diff->status |= 2;
return D_MISMATCH1;
}
if ((f[1].fp = openfile(diff, f[1].name, 1, 0)) == NULL) {
- warn("%s", f[1].name);
+ snprintf(diff->errbuf, sizeof(diff->errbuf),
+ "cmp_file: can't open '%s' (%s)", f[1].name, strerror(errno));
diff->status |= 2;
return D_MISMATCH1;
}
Index: othersrc/external/bsd/netdiff/dist/mem.c
diff -u othersrc/external/bsd/netdiff/dist/mem.c:1.1 othersrc/external/bsd/netdiff/dist/mem.c:1.2
--- othersrc/external/bsd/netdiff/dist/mem.c:1.1 Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/mem.c Wed Jan 16 01:50:19 2013
@@ -568,5 +568,5 @@ main(int argc, char **argv)
set_argstr(&diff, oargv, argv);
mmapdiff(&diff, argv[0], argv[1]);
diff_fini(&diff);
- exit(diff.status);
+ exit(diff_get_var(&diff, "(int)status", NULL, 0));
}
Index: othersrc/external/bsd/netdiff/dist/netdiff.h
diff -u othersrc/external/bsd/netdiff/dist/netdiff.h:1.5 othersrc/external/bsd/netdiff/dist/netdiff.h:1.6
--- othersrc/external/bsd/netdiff/dist/netdiff.h:1.5 Tue Jan 15 01:57:56 2013
+++ othersrc/external/bsd/netdiff/dist/netdiff.h Wed Jan 16 01:50:19 2013
@@ -59,6 +59,7 @@ typedef struct diff_t {
int inhibit; /* for word diff */
char *deleteregion[2];
char *insertregion[2];
+ char errbuf[256]; /* buffer for errors */
} diff_t;
diff_t *diff_init(void);
Index: othersrc/external/bsd/netdiff/dist/netwdiff.c
diff -u othersrc/external/bsd/netdiff/dist/netwdiff.c:1.3 othersrc/external/bsd/netdiff/dist/netwdiff.c:1.4
--- othersrc/external/bsd/netdiff/dist/netwdiff.c:1.3 Tue Jan 15 08:26:16 2013
+++ othersrc/external/bsd/netdiff/dist/netwdiff.c Wed Jan 16 01:50:19 2013
@@ -71,5 +71,5 @@ main(int argc, char **argv)
}
}
wdiff_file(&diff, argv[optind], argv[optind + 1]);
- exit(diff.status);
+ exit(diff_get_var(&diff, "(int)status", NULL, 0));
}