mirror of
https://git.savannah.gnu.org/git/tar.git
synced 2026-08-21 16:56:06 +00:00
Prefer C99 formats like %jd to doing it by hand
It’s now safe to assume support for C99 formats like %jd, so remove some of the longwinded formatting code put in only to be portable to pre-C99 platforms. * gnulib.modules: Add intprops. * src/buffer.c (format_total_stats, try_new_volume) (write_volume_label): * src/checkpoint.c (format_checkpoint_string): * src/compare.c (verify_volume): * src/create.c (to_chars_subst, dump_regular_file): * src/incremen.c (read_num): * src/list.c (read_and, from_header, simple_print_header) (print_for_mkdir): * src/sparse.c (sparse_dump_region): * src/system.c (dec_to_env, sys_exec_info_script) (sys_exec_checkpoint_script): * src/xheader.c (out_of_range_header): Prefer C99 formats like %jd and %ju to STRINGIFY_BIGINT. * src/common.h: Sort includes. Include intprops.h, verify.h. All other includes of verify.h removed. (intmax, uintmax): New functions and macros. (STRINGIFY_BIGINT): Remove; no longer used. (TIMESPEC_STRSIZE_BOUND): Make it 1 byte bigger, for negatives. * src/create.c (MAX_VAL_WITH_DIGITS, to_base256): Use *_WIDTH macros rather than assuming no padding bits. Prefer UINTMAX_MAX to (uintmax_t) -1. * src/list.c (tartime): Use strftime result rather than running strlen later. * src/misc.c (timetostr): New function. Prefer it when printing time_t values.
This commit is contained in:
+16
-8
@@ -372,7 +372,7 @@ replace_prefix (char **pname, const char *samp, size_t slen,
|
||||
/* Handling numbers. */
|
||||
|
||||
/* Convert VALUE, which is converted from a system integer type whose
|
||||
minimum value is MINVAL and maximum MINVAL, to an decimal
|
||||
minimum value is MINVAL and maximum MINVAL, to a decimal
|
||||
integer string. Use the storage in BUF and return a pointer to the
|
||||
converted string. If VALUE is converted from a negative integer in
|
||||
the range MINVAL .. -1, represent it with a string representation
|
||||
@@ -392,6 +392,14 @@ sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval,
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert T to a decimal integer string. Use the storage in BUF and
|
||||
return a pointer to the converted string. */
|
||||
char *
|
||||
timetostr (time_t t, char buf[SYSINT_BUFSIZE])
|
||||
{
|
||||
return sysinttostr (t, TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t), buf);
|
||||
}
|
||||
|
||||
/* Convert a prefix of the string ARG to a system integer type whose
|
||||
minimum value is MINVAL and maximum MAXVAL. If MINVAL is negative,
|
||||
negative integers MINVAL .. -1 are assumed to be represented using
|
||||
@@ -472,11 +480,10 @@ code_ns_fraction (int ns, char *p)
|
||||
}
|
||||
|
||||
char const *
|
||||
code_timespec (struct timespec t, char sbuf[TIMESPEC_STRSIZE_BOUND])
|
||||
code_timespec (struct timespec t, char tsbuf[TIMESPEC_STRSIZE_BOUND])
|
||||
{
|
||||
time_t s = t.tv_sec;
|
||||
int ns = t.tv_nsec;
|
||||
char *np;
|
||||
bool negative = s < 0;
|
||||
|
||||
/* ignore invalid values of ns */
|
||||
@@ -489,11 +496,12 @@ code_timespec (struct timespec t, char sbuf[TIMESPEC_STRSIZE_BOUND])
|
||||
ns = BILLION - ns;
|
||||
}
|
||||
|
||||
np = umaxtostr (negative ? - (uintmax_t) s : (uintmax_t) s, sbuf + 1);
|
||||
if (negative)
|
||||
*--np = '-';
|
||||
code_ns_fraction (ns, sbuf + UINTMAX_STRSIZE_BOUND);
|
||||
return np;
|
||||
bool minus_zero = negative & !s;
|
||||
char *sstr = timetostr (s, tsbuf + 1);
|
||||
sstr[-1] = '-';
|
||||
sstr -= minus_zero;
|
||||
code_ns_fraction (ns, sstr + strlen (sstr));
|
||||
return sstr;
|
||||
}
|
||||
|
||||
struct timespec
|
||||
|
||||
Reference in New Issue
Block a user