summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/string/string.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:18 +0000
commit5da14042f70711ea5cf66e034699730335462f66 (patch)
tree0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/libnetdata/string/string.c
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz
netdata-5da14042f70711ea5cf66e034699730335462f66.zip
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/libnetdata/string/string.c (renamed from libnetdata/string/string.c)23
1 files changed, 21 insertions, 2 deletions
diff --git a/libnetdata/string/string.c b/src/libnetdata/string/string.c
index e1c8352a5..0b4a6470d 100644
--- a/libnetdata/string/string.c
+++ b/src/libnetdata/string/string.c
@@ -88,8 +88,8 @@ void string_statistics(size_t *inserts, size_t *deletes, size_t *searches, size_
}
}
-#define string_entry_acquire(se) __atomic_add_fetch(&((se)->refcount), 1, __ATOMIC_SEQ_CST);
-#define string_entry_release(se) __atomic_sub_fetch(&((se)->refcount), 1, __ATOMIC_SEQ_CST);
+#define string_entry_acquire(se) __atomic_add_fetch(&((se)->refcount), 1, __ATOMIC_SEQ_CST)
+#define string_entry_release(se) __atomic_sub_fetch(&((se)->refcount), 1, __ATOMIC_SEQ_CST)
static inline bool string_entry_check_and_acquire(STRING *se) {
#ifdef NETDATA_INTERNAL_CHECKS
@@ -307,6 +307,25 @@ STRING *string_strdupz(const char *str) {
return string;
}
+STRING *string_strndupz(const char *str, size_t len) {
+ if(unlikely(!str || !*str || !len)) return NULL;
+
+#ifdef NETDATA_INTERNAL_CHECKS
+ uint8_t partition = string_partition_str(str);
+#endif
+
+ char buf[len + 1];
+ memcpy(buf, str, len);
+ buf[len] = '\0';
+
+ STRING *string = string_index_search(buf, len + 1);
+ while(!string)
+ string = string_index_insert(buf, len + 1);
+
+ string_stats_atomic_increment(partition, active_references);
+ return string;
+}
+
void string_freez(STRING *string) {
if(unlikely(!string)) return;