xref: /freebsd/contrib/atf/atf-c/detail/dynstr.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25 
26 #if !defined(ATF_C_DETAIL_DYNSTR_H)
27 #define ATF_C_DETAIL_DYNSTR_H
28 
29 #include <stdarg.h>
30 #include <stdbool.h>
31 #include <stddef.h>
32 
33 #include <atf-c/error_fwd.h>
34 
35 /* ---------------------------------------------------------------------
36  * The "atf_dynstr" type.
37  * --------------------------------------------------------------------- */
38 
39 struct atf_dynstr {
40     char *m_data;
41     size_t m_datasize;
42     size_t m_length;
43 };
44 typedef struct atf_dynstr atf_dynstr_t;
45 
46 /* Constants */
47 extern const size_t atf_dynstr_npos;
48 
49 /* Constructors and destructors */
50 atf_error_t atf_dynstr_init(atf_dynstr_t *);
51 atf_error_t atf_dynstr_init_ap(atf_dynstr_t *, const char *, va_list);
52 atf_error_t atf_dynstr_init_fmt(atf_dynstr_t *, const char *, ...);
53 atf_error_t atf_dynstr_init_raw(atf_dynstr_t *, const void *, size_t);
54 atf_error_t atf_dynstr_init_rep(atf_dynstr_t *, size_t, char);
55 atf_error_t atf_dynstr_init_substr(atf_dynstr_t *, const atf_dynstr_t *,
56                                    size_t, size_t);
57 atf_error_t atf_dynstr_copy(atf_dynstr_t *, const atf_dynstr_t *);
58 void atf_dynstr_fini(atf_dynstr_t *);
59 char *atf_dynstr_fini_disown(atf_dynstr_t *);
60 
61 /* Getters */
62 const char *atf_dynstr_cstring(const atf_dynstr_t *);
63 size_t atf_dynstr_length(const atf_dynstr_t *);
64 size_t atf_dynstr_rfind_ch(const atf_dynstr_t *, char);
65 
66 /* Modifiers */
67 atf_error_t atf_dynstr_append_ap(atf_dynstr_t *, const char *, va_list);
68 atf_error_t atf_dynstr_append_fmt(atf_dynstr_t *, const char *, ...);
69 void atf_dynstr_clear(atf_dynstr_t *);
70 atf_error_t atf_dynstr_prepend_ap(atf_dynstr_t *, const char *, va_list);
71 atf_error_t atf_dynstr_prepend_fmt(atf_dynstr_t *, const char *, ...);
72 
73 /* Operators */
74 bool atf_equal_dynstr_cstring(const atf_dynstr_t *, const char *);
75 bool atf_equal_dynstr_dynstr(const atf_dynstr_t *, const atf_dynstr_t *);
76 
77 #endif /* !defined(ATF_C_DETAIL_DYNSTR_H) */
78