Debian Codegraph @

src/lib/libdwarf/dwarf_string.h

raw
1 /*
2 Copyright (c) 2019-2023, 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 size_t s_size;
52 size_t 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 size_t len);
63
64 /* When you have an output of a limited length string
65 and can allocate a local array to hold it,
66 dwarfstring_constructor_static() is good since no malloc
67 is used unless the final string length exceeds the buffer
68 length. */
69 int dwarfstring_constructor_static(struct dwarfstring_s *g,
70 char * space, size_t len);
71 void dwarfstring_destructor(struct dwarfstring_s *g);
72 int dwarfstring_reset(struct dwarfstring_s *g);
73
74 int dwarfstring_append(struct dwarfstring_s *g,char *str);
75
76 /* When one wants the first 'len' characters of str
77 appended. NUL termination is provided by dwarfstrings. */
78 int dwarfstring_append_length(struct dwarfstring_s *g,
79 char *str,size_t len);
80
81 int dwarfstring_append_printf_s(dwarfstring *data,
82 char *format,char *s);
83 int dwarfstring_append_printf_i(dwarfstring *data,
84 char *format,dwarfstring_i);
85 int dwarfstring_append_printf_u(dwarfstring *data,
86 char *format,dwarfstring_u);
87
88 char * dwarfstring_string(struct dwarfstring_s *g);
89 size_t dwarfstring_strlen(struct dwarfstring_s *g);
90 #ifdef __cplusplus
91 }
92 #endif /* __cplusplus */
93 #endif /* DWARFSTRING_H */