diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -75,6 +75,17 @@ {NULL, no_argument, NULL, 0} }; +#ifdef SIGINFO +volatile sig_atomic_t info; + +static void +siginfo(int signo) +{ + + info = signo; +} +#endif + static void usage(void); static bool @@ -240,6 +251,9 @@ } } +#ifdef SIGINFO + (void)signal(SIGINFO, siginfo); +#endif if (special) c_special(fd1, file1, skip1, fd2, file2, skip2, limit); else { diff --git a/usr.bin/cmp/extern.h b/usr.bin/cmp/extern.h --- a/usr.bin/cmp/extern.h +++ b/usr.bin/cmp/extern.h @@ -46,3 +46,7 @@ void eofmsg(const char *); extern bool bflag, lflag, sflag, xflag, zflag; + +#ifdef SIGINFO +extern volatile sig_atomic_t info; +#endif diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c --- a/usr.bin/cmp/regular.c +++ b/usr.bin/cmp/regular.c @@ -120,6 +120,13 @@ p2 = m2 + (skip2 - off2); for (byte = line = 1; length--; ++byte) { +#ifdef SIGINFO + if (info) { + (void)fprintf(stderr, "%s %s char %zu line %zu\n", + file1, file2, (size_t)byte, (size_t)line); + info = 0; + } +#endif if ((ch = *p1) != *p2) { if (xflag) { dfound = 1; diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c --- a/usr.bin/cmp/special.c +++ b/usr.bin/cmp/special.c @@ -77,6 +77,13 @@ goto eof; for (byte = line = 1; limit == 0 || byte <= limit; ++byte) { +#ifdef SIGINFO + if (info) { + (void)fprintf(stderr, "%s %s char %zu line %zu\n", + file1, file2, (size_t)byte, (size_t)line); + info = 0; + } +#endif ch1 = getc(fp1); ch2 = getc(fp2); if (ch1 == EOF || ch2 == EOF)