tests: transform print_time_t into print_time_t_nsec
* tests/print_time.c (print_time_t): Rename to print_time_t_nsec, take second argument and print it. * tests/tests.h (print_time_t): Rename to print_time_t_nsec, add second argument. * tests/utime.c (main): Use print_time_t_nsec instead of print_time_t. * tests/xstatx.c (print_stat): Likewise. Pass nanoseconds to print_time_t_nsec instead of printing them.
This commit is contained in:
parent
0698ab728f
commit
bc41bcbb0b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Print time_t in symbolic format.
|
||||
* Print time_t and nanoseconds in symbolic format.
|
||||
*
|
||||
* Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
|
||||
* All rights reserved.
|
||||
@ -32,21 +32,24 @@
|
||||
#include <time.h>
|
||||
|
||||
void
|
||||
print_time_t(const time_t t)
|
||||
print_time_t_nsec(const time_t t, const unsigned long long nsec)
|
||||
{
|
||||
if (!t) {
|
||||
if (t) {
|
||||
const struct tm *const p = localtime(&t);
|
||||
|
||||
if (p) {
|
||||
char buf[256];
|
||||
|
||||
strftime(buf, sizeof(buf), "%FT%T%z", p);
|
||||
fputs(buf, stdout);
|
||||
} else {
|
||||
printf("%llu", zero_extend_signed_to_ull(t));
|
||||
}
|
||||
} else {
|
||||
putchar('0');
|
||||
return;
|
||||
}
|
||||
|
||||
const struct tm *const p = localtime(&t);
|
||||
|
||||
if (p) {
|
||||
char buf[256];
|
||||
|
||||
strftime(buf, sizeof(buf), "%FT%T%z", p);
|
||||
fputs(buf, stdout);
|
||||
} else {
|
||||
printf("%llu", zero_extend_signed_to_ull(t));
|
||||
if (nsec) {
|
||||
printf(".%09llu", nsec);
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ void print_quoted_string(const char *);
|
||||
/* Print memory in a quoted form. */
|
||||
void print_quoted_memory(const char *, size_t);
|
||||
|
||||
/* Print time_t in symbolic format. */
|
||||
void print_time_t(time_t);
|
||||
/* Print time_t and nanoseconds in symbolic format. */
|
||||
void print_time_t_nsec(time_t, unsigned long long);
|
||||
|
||||
/* Read an int from the file. */
|
||||
int read_int_from_file(const char *, int *);
|
||||
|
@ -69,9 +69,9 @@ main(void)
|
||||
rc = k_utime("utime\nfilename", tail_u);
|
||||
const char *errstr = sprintrc(rc);
|
||||
printf("utime(\"utime\\nfilename\", {actime=");
|
||||
print_time_t(t);
|
||||
print_time_t_nsec(t, 0);
|
||||
printf(", modtime=");
|
||||
print_time_t(t);
|
||||
print_time_t_nsec(t, 0);
|
||||
printf("}) = %s\n", errstr);
|
||||
|
||||
puts("+++ exited with 0 +++");
|
||||
|
@ -162,17 +162,15 @@ print_stat(const STRUCT_STAT *st)
|
||||
}
|
||||
|
||||
# if defined(HAVE_STRUCT_STAT_ST_MTIME_NSEC) && !OLD_STAT
|
||||
# define PRINT_TIME_NSEC(val) \
|
||||
if (val) \
|
||||
printf(".%09llu", zero_extend_signed_to_ull(val))
|
||||
# define TIME_NSEC(val) zero_extend_signed_to_ull(val)
|
||||
# else
|
||||
# define PRINT_TIME_NSEC(val)
|
||||
# define TIME_NSEC(val) 0
|
||||
# endif
|
||||
|
||||
# define PRINT_ST_TIME(field) \
|
||||
printf(", st_" #field "="); \
|
||||
print_time_t(sign_extend_unsigned_to_ll(st->st_ ## field)); \
|
||||
PRINT_TIME_NSEC(st->st_ ## field ## _nsec)
|
||||
print_time_t_nsec(sign_extend_unsigned_to_ll(st->st_ ## field), \
|
||||
TIME_NSEC(st->st_ ## field ## _nsec))
|
||||
|
||||
PRINT_ST_TIME(atime);
|
||||
PRINT_ST_TIME(mtime);
|
||||
|
Loading…
x
Reference in New Issue
Block a user