diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2022-11-16 03:17:36 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2022-11-16 03:17:36 +0000 |
| commit | 6100374ccf2644d3fd233bde8b8f4e73d9953c30 (patch) | |
| tree | dde186b3b5d945ba2db8e73cb217539b72872a03 | |
| parent | 4e0771714d6192119dcf7553b921bf88866d8925 (diff) | |
| -rw-r--r-- | usr.bin/diff/diffreg.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index b5e1f23b2d00..def8a4e05974 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1624,10 +1624,7 @@ static void print_header(const char *file1, const char *file2) { const char *time_format; - char buf1[256]; - char buf2[256]; - char end1[10]; - char end2[10]; + char buf[256]; struct tm tm1, tm2, *tm_ptr1, *tm_ptr2; int nsec1 = stb1.st_mtim.tv_nsec; int nsec2 = stb2.st_mtim.tv_nsec; @@ -1638,26 +1635,32 @@ print_header(const char *file1, const char *file2) time_format = "%c"; tm_ptr1 = localtime_r(&stb1.st_mtime, &tm1); tm_ptr2 = localtime_r(&stb2.st_mtime, &tm2); - strftime(buf1, 256, time_format, tm_ptr1); - strftime(buf2, 256, time_format, tm_ptr2); - if (!cflag) { - strftime(end1, 10, "%z", tm_ptr1); - strftime(end2, 10, "%z", tm_ptr2); - sprintf(buf1, "%s.%.9d %s", buf1, nsec1, end1); - sprintf(buf2, "%s.%.9d %s", buf2, nsec2, end2); - } if (label[0] != NULL) printf("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", label[0]); - else - printf("%s %s\t%s\n", diff_format == D_CONTEXT ? "***" : "---", - file1, buf1); + else { + strftime(buf, sizeof(buf), time_format, tm_ptr1); + printf("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---", + file1, buf); + if (!cflag) { + strftime(buf, sizeof(buf), "%z", tm_ptr1); + printf(".%.9d %s", nsec1, buf); + } + printf("\n"); + } if (label[1] != NULL) printf("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", label[1]); - else - printf("%s %s\t%s\n", diff_format == D_CONTEXT ? "---" : "+++", - file2, buf2); + else { + strftime(buf, sizeof(buf), time_format, tm_ptr2); + printf("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++", + file2, buf); + if (!cflag) { + strftime(buf, sizeof(buf), "%z", tm_ptr2); + printf(".%.9d %s", nsec2, buf); + } + printf("\n"); + } } /* |
