Branch
Hash :
dd6b4208
Author :
Date :
2025-05-11T02:55:11
string-desc: Fixes for string literals and older GCC versions. * lib/string-desc.h (HAVE__GENERIC, HAVE_BUILTIN_CHOOSE_EXPR, HAVE_BUILTIN_CONSTANT_P, HAVE_RW_STRING_DESC): New macros. Use HAVE_RW_STRING_DESC instead of HAVE_STATEMENT_EXPRESSIONS everywhere. (sd_new_addr): Use __builtin_choose_expr to deal with string literals. * lib/xstring-desc.h: Use HAVE_RW_STRING_DESC instead of HAVE_STATEMENT_EXPRESSIONS. * lib/string-buffer.c (sb_dupfree): Construct an empty writable string without a cast. * lib/xstring-buffer.c (sb_xdupfree): Likewise. * lib/string-buffer-reversed.c (sbr_dupfree): Likewise. * lib/xstring-buffer-reversed.c (sbr_xdupfree): Likewise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
/* Error-checking functions on a string buffer that accumulates from the end.
Copyright (C) 2024-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2025. */
#include <config.h>
/* Specification. */
#include "string-buffer-reversed.h"
#include "xalloc.h"
void
sbr_xprepend1 (struct string_buffer_reversed *buffer, char c)
{
if (sbr_prepend1 (buffer, c) < 0)
xalloc_die ();
}
void
sbr_xprepend_desc (struct string_buffer_reversed *buffer, string_desc_t s)
{
if (sbr_prepend_desc (buffer, s) < 0)
xalloc_die ();
}
void
sbr_xprepend_c (struct string_buffer_reversed *buffer, const char *str)
{
if (sbr_prepend_c (buffer, str) < 0)
xalloc_die ();
}
rw_string_desc_t
sbr_xdupfree (struct string_buffer_reversed *buffer)
{
if (buffer->error)
{
sbr_free (buffer);
return sd_readwrite (sd_new_empty ());
}
rw_string_desc_t contents = sbr_dupfree (buffer);
if (sd_data (contents) == NULL)
xalloc_die ();
return contents;
}
char *
sbr_xdupfree_c (struct string_buffer_reversed *buffer)
{
if (buffer->error)
{
sbr_free (buffer);
return NULL;
}
char *contents = sbr_dupfree_c (buffer);
if (contents == NULL)
xalloc_die ();
return contents;
}