summaryrefslogtreecommitdiffstats
path: root/libnetdata/buffer/buffer.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-30 18:47:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-30 18:47:05 +0000
commit97e01009d69b8fbebfebf68f51e3d126d0ed43fc (patch)
tree02e8b836c3a9d89806f3e67d4a5fe9f52dbb0061 /libnetdata/buffer/buffer.c
parentReleasing debian version 1.36.1-1. (diff)
downloadnetdata-97e01009d69b8fbebfebf68f51e3d126d0ed43fc.tar.xz
netdata-97e01009d69b8fbebfebf68f51e3d126d0ed43fc.zip
Merging upstream version 1.37.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/buffer/buffer.c')
-rw-r--r--libnetdata/buffer/buffer.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libnetdata/buffer/buffer.c b/libnetdata/buffer/buffer.c
index 8a32184f6..d0940588f 100644
--- a/libnetdata/buffer/buffer.c
+++ b/libnetdata/buffer/buffer.c
@@ -136,6 +136,66 @@ void buffer_print_llu(BUFFER *wb, unsigned long long uvalue)
wb->len += wstr - str;
}
+void buffer_print_ll(BUFFER *wb, long long value)
+{
+ buffer_need_bytes(wb, 50);
+
+ if(value < 0) {
+ buffer_fast_strcat(wb, "-", 1);
+ value = -value;
+ }
+
+ buffer_print_llu(wb, value);
+}
+
+static unsigned char bits03_to_hex[16] = {
+ [0] = '0',
+ [1] = '1',
+ [2] = '2',
+ [3] = '3',
+ [4] = '4',
+ [5] = '5',
+ [6] = '6',
+ [7] = '7',
+ [8] = '8',
+ [9] = '9',
+ [10] = 'A',
+ [11] = 'B',
+ [12] = 'C',
+ [13] = 'D',
+ [14] = 'E',
+ [15] = 'F'
+};
+
+void buffer_print_llu_hex(BUFFER *wb, unsigned long long value)
+{
+ unsigned char buffer[sizeof(unsigned long long) * 2 + 2 + 1]; // 8 bytes * 2 + '0x' + '\0'
+ unsigned char *e = &buffer[sizeof(unsigned long long) * 2 + 2];
+ unsigned char *p = e;
+
+ *p-- = '\0';
+ *p-- = bits03_to_hex[value & 0xF];
+ value >>= 4;
+ if(value) {
+ *p-- = bits03_to_hex[value & 0xF];
+ value >>= 4;
+
+ while(value) {
+ *p-- = bits03_to_hex[value & 0xF];
+ value >>= 4;
+
+ if(value) {
+ *p-- = bits03_to_hex[value & 0xF];
+ value >>= 4;
+ }
+ }
+ }
+ *p-- = 'x';
+ *p = '0';
+
+ buffer_fast_strcat(wb, (char *)p, e - p);
+}
+
void buffer_fast_strcat(BUFFER *wb, const char *txt, size_t len) {
if(unlikely(!txt || !*txt)) return;