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