Browse Source

print_timespec.h: parametrize TIMESPEC_T.tv_nsec

This is going to be used to implement a parser of SO_TIMESTAMP_NEW
control message.

* print_timespec.h [!TIMESPEC_NSEC] (TIMESPEC_NSEC): Define to tv_sec.
(TIMESPEC_TO_SEC_NSEC, timespec_fmt, print_timespec_t_utime): Use
TIMESPEC_NSEC instead of tv_sec.
Dmitry V. Levin 6 months ago
parent
commit
3f7ad363fb
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      print_timespec.h

+ 10
- 4
print_timespec.h View File

@@ -8,6 +8,10 @@
8 8
 
9 9
 #include "xstring.h"
10 10
 
11
+#ifndef TIMESPEC_NSEC
12
+# define TIMESPEC_NSEC tv_nsec
13
+#endif
14
+
11 15
 #ifndef UTIME_NOW
12 16
 # define UTIME_NOW ((1l << 30) - 1l)
13 17
 #endif
@@ -16,9 +20,11 @@
16 20
 #endif
17 21
 
18 22
 #define TIMESPEC_TO_SEC_NSEC(t_)	\
19
-	((long long) (t_)->tv_sec), zero_extend_signed_to_ull((t_)->tv_nsec)
23
+	((long long) (t_)->tv_sec),	\
24
+	 zero_extend_signed_to_ull((t_)->TIMESPEC_NSEC)
20 25
 
21
-static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}";
26
+static const char timespec_fmt[] =
27
+	"{tv_sec=%lld, " STRINGIFY_VAL(TIMESPEC_NSEC) "=%llu}";
22 28
 
23 29
 static void
24 30
 print_sec_nsec(long long sec, unsigned long long nsec)
@@ -110,7 +116,7 @@ SPRINT_TIMESPEC(struct tcb *const tcp, const kernel_ulong_t addr)
110 116
 static void
111 117
 print_timespec_t_utime(const TIMESPEC_T *t)
112 118
 {
113
-	switch (t->tv_nsec) {
119
+	switch (t->TIMESPEC_NSEC) {
114 120
 	case UTIME_NOW:
115 121
 	case UTIME_OMIT:
116 122
 		if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
@@ -119,7 +125,7 @@ print_timespec_t_utime(const TIMESPEC_T *t)
119 125
 			break;
120 126
 
121 127
 		(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
122
-			? tprints_comment : tprints)(t->tv_nsec == UTIME_NOW
128
+			? tprints_comment : tprints)(t->TIMESPEC_NSEC == UTIME_NOW
123 129
 				? "UTIME_NOW" : "UTIME_OMIT");
124 130
 		break;
125 131
 	default:

Loading…
Cancel
Save