exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / xstring-desc.h
blob36124cb1135f9fd836c8dd74a0dc1ee9baf189a3
1 /* String descriptors, with out-of-memory checking.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
19 #ifndef _XSTRING_DESC_H
20 #define _XSTRING_DESC_H 1
22 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
23 #if !_GL_CONFIG_H_INCLUDED
24 #error "Please include config.h first."
25 #endif
27 #include <string.h>
28 #include "string-desc.h"
29 #include "xalloc.h"
32 _GL_INLINE_HEADER_BEGIN
33 #ifndef GL_XSTRING_DESC_INLINE
34 # define GL_XSTRING_DESC_INLINE _GL_INLINE
35 #endif
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
42 /* ==== Memory-allocating operations on string descriptors ==== */
44 /* Return a string of length N, with uninitialized contents. */
45 #if 0 /* Defined inline below. */
46 extern string_desc_t xstring_desc_new (idx_t n);
47 #endif
49 /* Return a string of length N, filled with C. */
50 #if 0 /* Defined inline below. */
51 extern string_desc_t xstring_desc_new_filled (idx_t n, char c);
52 #endif
54 /* Return a copy of string S. */
55 #if 0 /* Defined inline below. */
56 extern string_desc_t xstring_desc_copy (string_desc_t s);
57 #endif
59 /* Return the concatenation of N strings. N must be > 0. */
60 extern string_desc_t xstring_desc_concat (idx_t n, string_desc_t string1, ...);
62 /* Construct and return a copy of string S, as a NUL-terminated C string. */
63 #if 0 /* Defined inline below. */
64 extern char * xstring_desc_c (string_desc_t s) _GL_ATTRIBUTE_DEALLOC_FREE;
65 #endif
68 /* ==== Inline function definitions ==== */
70 GL_XSTRING_DESC_INLINE string_desc_t
71 xstring_desc_new (idx_t n)
73 string_desc_t result;
74 if (string_desc_new (&result, n) < 0)
75 xalloc_die ();
76 return result;
79 GL_XSTRING_DESC_INLINE string_desc_t
80 xstring_desc_new_filled (idx_t n, char c)
82 string_desc_t result;
83 if (string_desc_new_filled (&result, n, c) < 0)
84 xalloc_die ();
85 return result;
88 GL_XSTRING_DESC_INLINE string_desc_t
89 xstring_desc_copy (string_desc_t s)
91 string_desc_t result;
92 if (string_desc_copy (&result, s) < 0)
93 xalloc_die ();
94 return result;
97 GL_XSTRING_DESC_INLINE
98 _GL_ATTRIBUTE_DEALLOC_FREE
99 char *
100 xstring_desc_c (string_desc_t s)
102 char *result = string_desc_c (s);
103 if (result == NULL)
104 xalloc_die ();
105 return result;
109 #ifdef __cplusplus
111 #endif
113 _GL_INLINE_HEADER_END
116 #endif /* _XSTRING_DESC_H */