xref: /illumos-gate/usr/src/lib/libdwarf/common/dwarfstring.h (revision 78801af7286cd73dbc996d470f789e75993cf15d)
1 /*
2 Copyright (c) 2019-2019, David Anderson
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with
6 or without modification, are permitted provided that the
7 following conditions are met:
8 
9     Redistributions of source code must retain the above
10     copyright notice, this list of conditions and the following
11     disclaimer.
12 
13     Redistributions in binary form must reproduce the above
14     copyright notice, this list of conditions and the following
15     disclaimer in the documentation and/or other materials
16     provided with the distribution.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 /*  A lightly generalized string buffer for libdwarf.
34     The functions that return anything return either
35     TRUE (nonzero int) or FALSE (zero)
36 
37     On return of FALSE the dwarfstring_s struct
38     remains in a usable state.
39 
40     It is expected that most users will not check the
41     return value.
42 */
43 #ifndef DWARFSTRING_H
44 #define DWARFSTRING_H
45 #ifdef __cplusplus
46 extern "C" {
47 #endif /* __cplusplus */
48 
49 struct dwarfstring_s {
50    char *        s_data;
51    unsigned long s_size;
52    unsigned long s_avail;
53    unsigned char s_malloc;
54 };
55 
56 typedef unsigned long long   dwarfstring_u;
57 typedef signed long long     dwarfstring_i;
58 typedef struct dwarfstring_s dwarfstring;
59 
60 int dwarfstring_constructor(struct dwarfstring_s *g);
61 int dwarfstring_constructor_fixed(struct dwarfstring_s *g,
62     unsigned long len);
63 int dwarfstring_constructor_static(struct dwarfstring_s *g,
64     char * space,
65     unsigned long len);
66 void dwarfstring_destructor(struct dwarfstring_s *g);
67 int dwarfstring_reset(struct dwarfstring_s *g);
68 
69 
70 int dwarfstring_append(struct dwarfstring_s *g,char *str);
71 
72 /*  When one wants the first 'len' characters of str
73     appended. NUL termination is provided by dwarfstrings. */
74 int dwarfstring_append_length(struct dwarfstring_s *g,
75     char *str,unsigned long len);
76 
77 int dwarfstring_append_printf_s(dwarfstring *data,
78     char *format,char *s);
79 int dwarfstring_append_printf_i(dwarfstring *data,
80     char *format,dwarfstring_i);
81 int dwarfstring_append_printf_u(dwarfstring *data,
82     char *format,dwarfstring_u);
83 
84 char * dwarfstring_string(struct dwarfstring_s *g);
85 unsigned long dwarfstring_strlen(struct dwarfstring_s *g);
86 #ifdef __cplusplus
87 }
88 #endif /* __cplusplus */
89 #endif /* DWARFSTRING_H */
90