diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 11:19:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:07:37 +0000 |
commit | b485aab7e71c1625cfc27e0f92c9509f42378458 (patch) | |
tree | ae9abe108601079d1679194de237c9a435ae5b55 /src/fluent-bit/lib/monkey/mk_core/mk_memory.c | |
parent | Adding upstream version 1.44.3. (diff) | |
download | netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.tar.xz netdata-b485aab7e71c1625cfc27e0f92c9509f42378458.zip |
Adding upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/lib/monkey/mk_core/mk_memory.c')
-rw-r--r-- | src/fluent-bit/lib/monkey/mk_core/mk_memory.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/fluent-bit/lib/monkey/mk_core/mk_memory.c b/src/fluent-bit/lib/monkey/mk_core/mk_memory.c new file mode 100644 index 000000000..c4073e231 --- /dev/null +++ b/src/fluent-bit/lib/monkey/mk_core/mk_memory.c @@ -0,0 +1,80 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Monkey HTTP Server + * ================== + * Copyright 2001-2017 Eduardo Silva <eduardo@monkey.io> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include <mk_core/mk_pthread.h> +#include <mk_core/mk_memory.h> +#include <mk_core/mk_macros.h> + +mk_ptr_t mk_ptr_create(char *buf, long init, long end) +{ + mk_ptr_t p; + + p.data = buf + init; + + if (init != end) { + p.len = (end - init); + } + else { + p.len = 1; + } + + return p; +} + +void mk_ptr_free(mk_ptr_t * p) +{ + mk_mem_free(p->data); + p->len = 0; +} + +char *mk_ptr_to_buf(mk_ptr_t p) +{ + char *buf; + + buf = mk_mem_alloc(p.len + 1); + if (!buf) return NULL; + + memcpy(buf, p.data, p.len); + buf[p.len] = '\0'; + + return (char *) buf; +} + +void mk_ptr_print(mk_ptr_t p) +{ + unsigned int i; + + printf("\nDEBUG MK_POINTER: '"); + for (i = 0; i < p.len && p.data != NULL; i++) { + printf("%c", p.data[i]); + } + printf("'"); + fflush(stdout); +} + +void mk_ptr_set(mk_ptr_t *p, char *data) +{ + p->data = data; + p->len = strlen(data); +} |