summaryrefslogtreecommitdiffstats
path: root/Meter.h
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-24 19:34:27 +0100
committerBenny Baumann <BenBE@geshi.org>2020-12-06 16:03:44 +0100
commitad764ff972082608604634c84e5427e7bfdcda1a (patch)
tree3b4cb72205d708563bd9baf62ef2039dc8bafdac /Meter.h
parent77ec86aff4314afd893baed0d16d7bd52c387fd4 (diff)
Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers
Closes: #294
Diffstat (limited to 'Meter.h')
-rw-r--r--Meter.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/Meter.h b/Meter.h
index 13cbebba..cb054057 100644
--- a/Meter.h
+++ b/Meter.h
@@ -20,6 +20,29 @@ in the source distribution for its full text.
#define METER_BUFFER_LEN 256
+#define METER_BUFFER_CHECK(buffer, size, written) \
+ do { \
+ if ((written) < 0 || (size_t)(written) >= (size)) { \
+ return; \
+ } \
+ (buffer) += (written); \
+ (size) -= (size_t)(written); \
+ } while (0)
+
+#define METER_BUFFER_APPEND_CHR(buffer, size, c) \
+ do { \
+ if ((size) < 2) { \
+ return; \
+ } \
+ *(buffer)++ = c; \
+ *(buffer) = '\0'; \
+ (size)--; \
+ if ((size) == 0) { \
+ return; \
+ } \
+ } while (0)
+
+
struct Meter_;
typedef struct Meter_ Meter;

© 2014-2024 Faster IT GmbH | imprint | privacy policy