From c21c3b0befeb46a51b6bf3758ffa30813bea0ff0 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 9 Mar 2024 14:19:22 +0100 Subject: Adding upstream version 1.44.3. Signed-off-by: Daniel Baumann --- fluent-bit/lib/monkey/mk_core/mk_memory.c | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 fluent-bit/lib/monkey/mk_core/mk_memory.c (limited to 'fluent-bit/lib/monkey/mk_core/mk_memory.c') diff --git a/fluent-bit/lib/monkey/mk_core/mk_memory.c b/fluent-bit/lib/monkey/mk_core/mk_memory.c new file mode 100644 index 000000000..c4073e231 --- /dev/null +++ b/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 + * + * 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 +#include +#include + +#include +#include +#include + +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); +} -- cgit v1.2.3