exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / striconv.h
blobcb42c7b19fd5547d211dc6f67a93e3acedc2d5f3
1 /* Charset conversion.
2 Copyright (C) 2001-2004, 2006-2007, 2009-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible and Simon Josefsson.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef _STRICONV_H
19 #define _STRICONV_H
21 /* This file uses _GL_ATTRIBUTE_MALLOC, HAVE_ICONV. */
22 #if !_GL_CONFIG_H_INCLUDED
23 #error "Please include config.h first."
24 #endif
26 #include <stdlib.h>
27 #if HAVE_ICONV
28 #include <iconv.h>
29 #endif
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
37 #if HAVE_ICONV
39 /* Convert an entire string from one encoding to another, using iconv.
40 The original string is at [SRC,...,SRC+SRCLEN-1].
41 The conversion descriptor is passed as CD.
42 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
43 or *RESULTP can initially be NULL.
44 May erase the contents of the memory at *RESULTP.
45 Return value: 0 if successful, otherwise -1 and errno set.
46 If successful: The resulting string is stored in *RESULTP and its length
47 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
48 unchanged if no dynamic memory allocation was necessary. */
49 extern int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
50 char **resultp, size_t *lengthp);
52 /* Convert an entire string from one encoding to another, using iconv.
53 The original string is the NUL-terminated string starting at SRC.
54 The conversion descriptor is passed as CD. Both the "from" and the "to"
55 encoding must use a single NUL byte at the end of the string (i.e. not
56 UCS-2, UCS-4, UTF-16, UTF-32).
57 Allocate a malloced memory block for the result.
58 Return value: the freshly allocated resulting NUL-terminated string if
59 successful, otherwise NULL and errno set. */
60 extern char * str_cd_iconv (const char *src, iconv_t cd)
61 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
63 #endif
65 /* Convert an entire string from one encoding to another, using iconv.
66 The original string is the NUL-terminated string starting at SRC.
67 Both the "from" and the "to" encoding must use a single NUL byte at the
68 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
69 Allocate a malloced memory block for the result.
70 Return value: the freshly allocated resulting NUL-terminated string if
71 successful, otherwise NULL and errno set. */
72 extern char * str_iconv (const char *src,
73 const char *from_codeset, const char *to_codeset)
74 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
77 #ifdef __cplusplus
79 #endif
82 #endif /* _STRICONV_H */