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