diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-11-24 19:34:27 +0100 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2020-12-06 16:03:44 +0100 |
commit | ad764ff972082608604634c84e5427e7bfdcda1a (patch) | |
tree | 3b4cb72205d708563bd9baf62ef2039dc8bafdac /linux/ZramMeter.c | |
parent | 77ec86aff4314afd893baed0d16d7bd52c387fd4 (diff) |
Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers
Closes: #294
Diffstat (limited to 'linux/ZramMeter.c')
-rw-r--r-- | linux/ZramMeter.c | 35 |
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); } |