/*
- * 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.
#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) {
- putchar('0');
- return;
- }
-
- const struct tm *const p = localtime(&t);
+ if (t) {
+ const struct tm *const p = localtime(&t);
- if (p) {
- char buf[256];
+ if (p) {
+ char buf[256];
- strftime(buf, sizeof(buf), "%FT%T%z", p);
- fputs(buf, stdout);
+ strftime(buf, sizeof(buf), "%FT%T%z", p);
+ fputs(buf, stdout);
+ } else {
+ printf("%llu", zero_extend_signed_to_ull(t));
+ }
} else {
- printf("%llu", zero_extend_signed_to_ull(t));
+ putchar('0');
+ }
+
+ if (nsec) {
+ printf(".%09llu", nsec);
}
}
/* 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 *);
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 +++");
}
# 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);