mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Better formatting for pax extended header times
As specified, don't include the subsecond part if zero and drop trailing zeros in the subsecond part. ok millert@
This commit is contained in:
parent
38558285c9
commit
b54e157770
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: tar.c,v 1.78 2023/12/27 08:29:41 jca Exp $ */
|
/* $OpenBSD: tar.c,v 1.79 2024/01/20 17:34:50 jca Exp $ */
|
||||||
/* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */
|
/* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
@ -984,13 +984,28 @@ xheader_add_ts(struct xheader *xhdr, const char *keyword,
|
|||||||
{
|
{
|
||||||
struct xheader_record *rec;
|
struct xheader_record *rec;
|
||||||
int reclen, tmplen;
|
int reclen, tmplen;
|
||||||
|
char frac[sizeof(".111222333")] = "";
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
|
/* Only write subsecond part if non-zero */
|
||||||
|
if (value->tv_nsec != 0) {
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = snprintf(frac, sizeof(frac), ".%09ld",
|
||||||
|
(long)value->tv_nsec);
|
||||||
|
if (n <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Zap trailing zeros */
|
||||||
|
for (n--; n > 1 && frac[n] == '0'; n--)
|
||||||
|
frac[n] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
tmplen = MINXHDRSZ;
|
tmplen = MINXHDRSZ;
|
||||||
do {
|
do {
|
||||||
reclen = tmplen;
|
reclen = tmplen;
|
||||||
tmplen = snprintf(NULL, 0, "%d %s=%lld.%09ld\n", reclen,
|
tmplen = snprintf(NULL, 0, "%d %s=%lld%s\n", reclen,
|
||||||
keyword, (long long)value->tv_sec, (long)value->tv_nsec);
|
keyword, (long long)value->tv_sec, frac);
|
||||||
} while (tmplen >= 0 && tmplen != reclen);
|
} while (tmplen >= 0 && tmplen != reclen);
|
||||||
if (tmplen < 0)
|
if (tmplen < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -999,8 +1014,8 @@ xheader_add_ts(struct xheader *xhdr, const char *keyword,
|
|||||||
if (rec == NULL)
|
if (rec == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
rec->reclen = reclen;
|
rec->reclen = reclen;
|
||||||
if (asprintf(&s, "%d %s=%lld.%09ld\n", reclen, keyword,
|
if (asprintf(&s, "%d %s=%lld%s\n", reclen, keyword,
|
||||||
(long long)value->tv_sec, (long)value->tv_nsec) < 0) {
|
(long long)value->tv_sec, frac) < 0) {
|
||||||
free(rec);
|
free(rec);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user