]> granicus.if.org Git - strace/blob - print_time.c
Mpersify parsers of utimes, futimesat, and utimensat syscalls
[strace] / print_time.c
1 #include "defs.h"
2
3 #include DEF_MPERS_TYPE(timespec_t)
4 #include DEF_MPERS_TYPE(timeval_t)
5
6 typedef struct timespec timespec_t;
7 typedef struct timeval timeval_t;
8
9 #include MPERS_DEFS
10
11 #ifndef UTIME_NOW
12 # define UTIME_NOW ((1l << 30) - 1l)
13 #endif
14 #ifndef UTIME_OMIT
15 # define UTIME_OMIT ((1l << 30) - 2l)
16 #endif
17
18 static void
19 print_timespec_t_utime(struct tcb *tcp, const timespec_t *t)
20 {
21         switch (t->tv_nsec) {
22         case UTIME_NOW:
23                 tprints("UTIME_NOW");
24                 break;
25         case UTIME_OMIT:
26                 tprints("UTIME_OMIT");
27                 break;
28         default:
29                 tprintf("{%jd, %jd}",
30                         (intmax_t) t->tv_sec, (intmax_t) t->tv_nsec);
31                 break;
32         }
33 }
34
35 static void
36 print_timeval_t(struct tcb *tcp, const timeval_t *t)
37 {
38         tprintf("{%jd, %jd}", (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
39 }
40
41 MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long addr)
42 {
43         timespec_t t[2];
44
45         if (umove_or_printaddr(tcp, addr, &t))
46                 return;
47
48         tprints("[");
49         print_timespec_t_utime(tcp, &t[0]);
50         tprints(", ");
51         print_timespec_t_utime(tcp, &t[1]);
52         tprints("]");
53 }
54
55 MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr)
56 {
57         timeval_t t[2];
58
59         if (umove_or_printaddr(tcp, addr, &t))
60                 return;
61
62         tprints("[");
63         print_timeval_t(tcp, &t[0]);
64         tprints(", ");
65         print_timeval_t(tcp, &t[1]);
66         tprints("]");
67 }