Introduce METER_BUFFER_CHECK and METER_BUFFER_APPEND_CHR to cleanup writing to bar buffers

Closes: #294
This commit is contained in:
Christian Göttsche
2020-11-24 19:34:27 +01:00
committed by Benny Baumann
parent 77ec86aff4
commit ad764ff972
6 changed files with 53 additions and 48 deletions

23
Meter.h
View File

@ -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;