hc
2023-11-22 d0a428a6556ea5a006e22e28b0b1cd037885fe20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From 20e2c61fc04a291250acee649c2523d2546cedea Mon Sep 17 00:00:00 2001
From: Andrea Adami <andrea.adami@gmail.com>
Date: Tue, 17 Apr 2018 13:14:12 +0200
Subject: [PATCH] vmcore-dmesg.c: work around missing imaxdiv()
 
Convert to integer arithmetic for klibc.
 
Fix
 
 vmcore-dmesg.c: In function 'dump_dmesg_structured':
 vmcore-dmesg.c:578:2: error: unknown type name 'imaxdiv_t'
 
Upstream-Status: Inappropriate [klibc specific]
Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
 
---
 vmcore-dmesg/vmcore-dmesg.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
 
diff --git a/vmcore-dmesg/vmcore-dmesg.c b/vmcore-dmesg/vmcore-dmesg.c
index 7972788..c63ac4f 100644
--- a/vmcore-dmesg/vmcore-dmesg.c
+++ b/vmcore-dmesg/vmcore-dmesg.c
@@ -575,8 +575,11 @@ static void dump_dmesg_structured(int fd)
     ssize_t ret;
     char *msg;
     uint16_t text_len;
+#ifndef __KLIBC__
     imaxdiv_t imaxdiv_sec, imaxdiv_usec;
-
+#else
+    int64_t imaxdiv_sec, imaxdiv_usec;
+#endif
     if (!log_buf_vaddr) {
         fprintf(stderr, "Missing the log_buf symbol\n");
         exit(60);
@@ -645,12 +648,20 @@ static void dump_dmesg_structured(int fd)
             exit(65);
         }
         ts_nsec = struct_val_u64(buf, log_offset_ts_nsec);
+#ifndef __KLIBC__
         imaxdiv_sec = imaxdiv(ts_nsec, 1000000000);
         imaxdiv_usec = imaxdiv(imaxdiv_sec.rem, 1000);
 
         len += sprintf(out_buf + len, "[%5llu.%06llu] ",
             (long long unsigned int)imaxdiv_sec.quot,
             (long long unsigned int)imaxdiv_usec.quot);
+#else
+        imaxdiv_sec = ts_nsec / 1000000000;
+        imaxdiv_usec = (ts_nsec % 1000000000) / 1000;
+        len += sprintf(out_buf + len, "[%5llu.%06llu] ",
+            (long long unsigned int)imaxdiv_sec,
+            (long long unsigned int)imaxdiv_usec);
+#endif
 
         /* escape non-printable characters */
         text_len = struct_val_u16(buf, log_offset_text_len);