2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2019 The strace developers.
6 * SPDX-License-Identifier: LGPL-2.1-or-later
12 # define TIMESPEC_NSEC tv_nsec
16 # define UTIME_NOW ((1l << 30) - 1l)
19 # define UTIME_OMIT ((1l << 30) - 2l)
22 #define TIMESPEC_TO_SEC_NSEC(t_) \
23 ((long long) (t_)->tv_sec), \
24 zero_extend_signed_to_ull((t_)->TIMESPEC_NSEC)
26 static const char timespec_fmt[] =
27 "{tv_sec=%lld, " STRINGIFY_VAL(TIMESPEC_NSEC) "=%llu}";
30 print_sec_nsec(long long sec, unsigned long long nsec)
32 tprintf(timespec_fmt, sec, nsec);
36 print_timespec_t(const TIMESPEC_T *t)
38 print_sec_nsec(TIMESPEC_TO_SEC_NSEC(t));
41 #ifdef PRINT_TIMESPEC_DATA_SIZE
43 PRINT_TIMESPEC_DATA_SIZE(const void *arg, const size_t size)
45 if (size < sizeof(TIMESPEC_T)) {
50 print_timespec_t(arg);
53 #endif /* PRINT_TIMESPEC_DATA_SIZE */
55 #ifdef PRINT_TIMESPEC_ARRAY_DATA_SIZE
57 PRINT_TIMESPEC_ARRAY_DATA_SIZE(const void *arg, const unsigned int nmemb,
60 const TIMESPEC_T *ts = arg;
63 if (nmemb > size / sizeof(TIMESPEC_T)) {
70 for (i = 0; i < nmemb; i++) {
73 print_timespec_t(&ts[i]);
79 #endif /* PRINT_TIMESPEC_ARRAY_DATA_SIZE */
83 PRINT_TIMESPEC(struct tcb *const tcp, const kernel_ulong_t addr)
87 if (umove_or_printaddr(tcp, addr, &t))
93 #endif /* PRINT_TIMESPEC */
95 #ifdef SPRINT_TIMESPEC
97 SPRINT_TIMESPEC(struct tcb *const tcp, const kernel_ulong_t addr)
100 static char buf[sizeof(timespec_fmt) + 3 * sizeof(t)];
104 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
105 umove(tcp, addr, &t)) {
106 xsprintf(buf, "%#" PRI_klx, addr);
108 xsprintf(buf, timespec_fmt, TIMESPEC_TO_SEC_NSEC(&t));
113 #endif /* SPRINT_TIMESPEC */
115 #ifdef PRINT_TIMESPEC_UTIME_PAIR
117 print_timespec_t_utime(const TIMESPEC_T *t)
119 switch (t->TIMESPEC_NSEC) {
122 if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
124 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
127 (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
128 ? tprints_comment : tprints)(t->TIMESPEC_NSEC == UTIME_NOW
129 ? "UTIME_NOW" : "UTIME_OMIT");
133 tprints_comment(sprinttime_nsec(TIMESPEC_TO_SEC_NSEC(t)));
139 PRINT_TIMESPEC_UTIME_PAIR(struct tcb *const tcp, const kernel_ulong_t addr)
143 if (umove_or_printaddr(tcp, addr, &t))
147 print_timespec_t_utime(&t[0]);
149 print_timespec_t_utime(&t[1]);
153 #endif /* PRINT_TIMESPEC_UTIME_PAIR */
155 #ifdef PRINT_ITIMERSPEC
157 PRINT_ITIMERSPEC(struct tcb *const tcp, const kernel_ulong_t addr)
161 if (umove_or_printaddr(tcp, addr, &t))
164 tprints("{it_interval=");
165 print_timespec_t(&t[0]);
166 tprints(", it_value=");
167 print_timespec_t(&t[1]);
171 #endif /* PRINT_ITIMERSPEC */