mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-22 18:55:29 +03:00
108 lines
3.2 KiB
Diff
108 lines
3.2 KiB
Diff
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);
|