xref: /illumos-gate/usr/src/uts/common/sys/ilstr.h (revision 43379a280422204006ceee5a5c5380444cb515d9)
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 2024 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 #include <stddef.h>
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 typedef enum ilstr_errno {
32 	ILSTR_ERROR_OK = 0,
33 	ILSTR_ERROR_NOMEM,
34 	ILSTR_ERROR_OVERFLOW,
35 	ILSTR_ERROR_PRINTF,
36 } ilstr_errno_t;
37 
38 typedef enum ilstr_flag {
39 	ILSTR_FLAG_PREALLOC = (1 << 0),
40 } ilstr_flag_t;
41 
42 typedef struct ilstr {
43 	char *ils_data;
44 	size_t ils_datalen;
45 	size_t ils_strlen;
46 	ilstr_errno_t ils_errno;
47 	int ils_kmflag;
48 	ilstr_flag_t ils_flag;
49 } ilstr_t;
50 
51 extern void ilstr_init(ilstr_t *, int);
52 extern void ilstr_init_prealloc(ilstr_t *, char *, size_t);
53 extern void ilstr_reset(ilstr_t *);
54 extern void ilstr_fini(ilstr_t *);
55 extern void ilstr_append_str(ilstr_t *, const char *);
56 extern void ilstr_append_char(ilstr_t *, char);
57 extern ilstr_errno_t ilstr_errno(ilstr_t *);
58 extern const char *ilstr_cstr(ilstr_t *);
59 extern size_t ilstr_len(ilstr_t *);
60 extern const char *ilstr_errstr(ilstr_t *);
61 void ilstr_aprintf(ilstr_t *, const char *, ...);
62 void ilstr_vaprintf(ilstr_t *, const char *, va_list);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif /* _SYS_ILSTR_H */
69