1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2023 Oxide Computer Company 14 */ 15 16 #ifndef _SYS_ILSTR_H 17 #define _SYS_ILSTR_H 18 19 #ifdef _KERNEL 20 #include <sys/types.h> 21 #include <sys/varargs.h> 22 #else 23 #include <stdarg.h> 24 #endif 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 typedef enum ilstr_errno { 31 ILSTR_ERROR_OK = 0, 32 ILSTR_ERROR_NOMEM, 33 ILSTR_ERROR_OVERFLOW, 34 ILSTR_ERROR_PRINTF, 35 } ilstr_errno_t; 36 37 typedef enum ilstr_flag { 38 ILSTR_FLAG_PREALLOC = (1 << 0), 39 } ilstr_flag_t; 40 41 typedef struct ilstr { 42 char *ils_data; 43 size_t ils_datalen; 44 size_t ils_strlen; 45 ilstr_errno_t ils_errno; 46 int ils_kmflag; 47 ilstr_flag_t ils_flag; 48 } ilstr_t; 49 50 extern void ilstr_init(ilstr_t *, int); 51 extern void ilstr_init_prealloc(ilstr_t *, char *, size_t); 52 extern void ilstr_reset(ilstr_t *); 53 extern void ilstr_fini(ilstr_t *); 54 extern void ilstr_append_str(ilstr_t *, const char *); 55 extern void ilstr_append_char(ilstr_t *, char); 56 extern ilstr_errno_t ilstr_errno(ilstr_t *); 57 extern const char *ilstr_cstr(ilstr_t *); 58 extern size_t ilstr_len(ilstr_t *); 59 extern const char *ilstr_errstr(ilstr_t *); 60 void ilstr_aprintf(ilstr_t *, const char *, ...); 61 void ilstr_vaprintf(ilstr_t *, const char *, va_list); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif /* _SYS_ILSTR_H */ 68