summaryrefslogtreecommitdiffstats
path: root/linux
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 /linux
parent77ec86aff4314afd893baed0d16d7bd52c387fd4 (diff)
Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers
Closes: #294
Diffstat (limited to 'linux')
-rw-r--r--linux/ZramMeter.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c
index 35148871..e6b6937e 100644
--- a/linux/ZramMeter.c
+++ b/linux/ZramMeter.c
@@ -20,32 +20,17 @@ static void ZramMeter_updateValues(Meter* this, char* buffer, size_t size) {
this->curItems = 1;
written = Meter_humanUnit(buffer, this->values[0], size);
- buffer += written;
- size -= written;
- if (size <= 0) {
- return;
- }
- *buffer++ = '(';
- size--;
- if (size <= 0) {
- return;
- }
+ METER_BUFFER_CHECK(buffer, size, written);
+
+ METER_BUFFER_APPEND_CHR(buffer, size, '(');
+
written = Meter_humanUnit(buffer, this->values[1], size);
- buffer += written;
- size -= written;
- if (size <= 0) {
- return;
- }
- *buffer++ = ')';
- size--;
- if (size <= 0) {
- return;
- }
- *buffer++ = '/';
- size--;
- if (size <= 0) {
- return;
- }
+ METER_BUFFER_CHECK(buffer, size, written);
+
+ METER_BUFFER_APPEND_CHR(buffer, size, ')');
+
+ METER_BUFFER_APPEND_CHR(buffer, size, '/');
+
Meter_humanUnit(buffer, this->total, size);
}

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