Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2023 Napatech A/S 3 : : */ 4 : : 5 : : #include "ntlog.h" 6 : : 7 : : #include <stdarg.h> 8 : : #include <stddef.h> 9 : : #include <string.h> 10 : : #include <stdlib.h> 11 : : #include <stdbool.h> 12 : : 13 : : #include <rte_log.h> 14 : : #include <rte_string_fns.h> 15 : : 16 : : #define NTLOG_HELPER_STR_SIZE_MAX (1024) 17 : : 18 : 0 : char *nthw_log_helper_str_alloc(const char *sinit) 19 : : { 20 : 0 : char *s = malloc(NTLOG_HELPER_STR_SIZE_MAX); 21 : : 22 [ # # ]: 0 : if (!s) 23 : : return NULL; 24 : : 25 [ # # ]: 0 : if (sinit) 26 : : snprintf(s, NTLOG_HELPER_STR_SIZE_MAX, "%s", sinit); 27 : : 28 : : else 29 : 0 : s[0] = '\0'; 30 : : 31 : : return s; 32 : : } 33 : : 34 : : __rte_format_printf(2, 0) 35 : 0 : void nthw_log_helper_str_add(char *s, const char *format, ...) 36 : : { 37 [ # # ]: 0 : if (!s) 38 : 0 : return; 39 : : 40 : : va_list args; 41 : 0 : va_start(args, format); 42 : 0 : int len = strlen(s); 43 : 0 : vsnprintf(&s[len], (NTLOG_HELPER_STR_SIZE_MAX - 1 - len), format, args); 44 : 0 : va_end(args); 45 : : } 46 : : 47 : 0 : void nthw_log_helper_str_free(char *s) 48 : : { 49 : 0 : free(s); 50 : 0 : }