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 /Meter.h | |
parent | 77ec86aff4314afd893baed0d16d7bd52c387fd4 (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.h | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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; |