Download raw body.
pax: write more correct extender header file times
The spec[0] says that when handling the subsecond part of a timestamp we
should "generate only enough digits", so trailing zeros should be
omitted. Actually the period and subsecond part should be completely
omitted if the subsecond part is zero.
ok?
[0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_05
Index: tar.c
===================================================================
RCS file: /home/cvs/src/bin/pax/tar.c,v
diff -u -p -p -u -r1.78 tar.c
--- tar.c 27 Dec 2023 08:29:41 -0000 1.78
+++ tar.c 20 Jan 2024 14:29:02 -0000
@@ -984,13 +984,28 @@ xheader_add_ts(struct xheader *xhdr, con
{
struct xheader_record *rec;
int reclen, tmplen;
+ char frac[sizeof(".111222333")] = "";
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;
do {
reclen = tmplen;
- tmplen = snprintf(NULL, 0, "%d %s=%lld.%09ld\n", reclen,
- keyword, (long long)value->tv_sec, (long)value->tv_nsec);
+ tmplen = snprintf(NULL, 0, "%d %s=%lld%s\n", reclen,
+ keyword, (long long)value->tv_sec, frac);
} while (tmplen >= 0 && tmplen != reclen);
if (tmplen < 0)
return -1;
@@ -999,8 +1014,8 @@ xheader_add_ts(struct xheader *xhdr, con
if (rec == NULL)
return -1;
rec->reclen = reclen;
- if (asprintf(&s, "%d %s=%lld.%09ld\n", reclen, keyword,
- (long long)value->tv_sec, (long)value->tv_nsec) < 0) {
+ if (asprintf(&s, "%d %s=%lld%s\n", reclen, keyword,
+ (long long)value->tv_sec, frac) < 0) {
free(rec);
return -1;
}
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
pax: write more correct extender header file times