aboutsummaryrefslogtreecommitdiffstats
path: root/community/hdrhistogram-c/use-custom-hdr_getline-func-for-all-platforms.patch
blob: 06780413401919159f34786449b6973d8f0fc477 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
From 8367213bc68641d6ee34a4e21ad14ad2a7427030 Mon Sep 17 00:00:00 2001
From: Michael Barker <mikeb01@gmail.com>
Date: Sat, 16 May 2020 16:48:42 +1200
Subject: [PATCH] Use custom hdr_getline function for all platforms.

Patch-Source: https://github.com/HdrHistogram/HdrHistogram_c/commit/8367213bc68641d6ee34a4e21ad14ad2a7427030
Upstream-Issue: https://github.com/HdrHistogram/HdrHistogram_c/issues/79

---
 src/hdr_encoding.c            |  2 +-
 src/hdr_histogram_log.c       | 30 +++++++++++++-----------------
 test/hdr_histogram_log_test.c |  4 ++++
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/hdr_histogram_log.c b/src/hdr_histogram_log.c
index bb13861..ad02695 100644
--- a/src/hdr_histogram_log.c
+++ b/src/hdr_histogram_log.c
@@ -981,16 +981,16 @@ static void update_timespec(hdr_timespec* ts, double timestamp)
     hdr_timespec_from_double(ts, timestamp);
 }
 
-#if defined(_MSC_VER)
-
 static ssize_t hdr_read_chunk(char* buffer, size_t length, char terminator, FILE* stream)
 {
+    size_t i;
+
     if (buffer == NULL || length == 0)
     {
         return -1;
     }
 
-    for (size_t i = 0; i < length; ++i)
+    for (i = 0; i < length; ++i)
     {
         int c = fgetc(stream);
         buffer[i] = (char)c;
@@ -1007,20 +1007,24 @@ static ssize_t hdr_read_chunk(char* buffer, size_t length, char terminator, FILE
 /* Note that this version of getline assumes lineptr is valid. */
 static ssize_t hdr_getline(char** lineptr, FILE* stream)
 {
+    size_t allocation = 128;
+    size_t used = 0;
+    char* scratch = NULL;
+    char* before;
+    size_t wanted;
+    size_t read_length;
+
     if (stream == NULL)
     {
         return -1;
     }
 
-    size_t allocation = 128;
-    size_t used = 0;
 
-    char* scratch = NULL;
     for (;;)
     {
         allocation += allocation;
 
-        char* before = scratch;
+        before = scratch;
         scratch = realloc(scratch, allocation);
         if (scratch == NULL)
         {
@@ -1031,8 +1035,8 @@ static ssize_t hdr_getline(char** lineptr, FILE* stream)
             return -1;
         }
 
-        size_t wanted = allocation - used - 1;
-        size_t read_length = hdr_read_chunk(scratch + used, wanted, '\n', stream);
+        wanted = allocation - used - 1;
+        read_length = hdr_read_chunk(scratch + used, wanted, '\n', stream);
         used += read_length;
 
 
@@ -1045,14 +1049,6 @@ static ssize_t hdr_getline(char** lineptr, FILE* stream)
     }
 }
 
-#else
-static ssize_t hdr_getline(char** lineptr, FILE* stream)
-{
-    size_t line_length = 0;
-    return getline(lineptr, &line_length, stream);
-}
-#endif
-
 int hdr_log_read(
     struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
     hdr_timespec* timestamp, hdr_timespec* interval)
diff --git a/test/hdr_histogram_log_test.c b/test/hdr_histogram_log_test.c
index 61cc626..72bdb28 100644
--- a/test/hdr_histogram_log_test.c
+++ b/test/hdr_histogram_log_test.c
@@ -836,6 +836,10 @@ static char* decode_v3_log()
     const char* v3_log = "jHiccup-2.0.7S.logV3.hlog";
 
     FILE* f = fopen(v3_log, "r");
+    if (NULL == f)
+    {
+        fprintf(stderr, "Open file: [%d] %s", errno, strerror(errno));
+    }
     mu_assert("Can not open v3 log file", f != NULL);
 
     hdr_init(1, INT64_C(3600000000000), 3, &accum);