xref: /netbsd-src/external/gpl2/gettext/dist/gettext-runtime/gnulib-lib/striconv.h (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1*946379e7Schristos /* Charset conversion.
2*946379e7Schristos    Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc.
3*946379e7Schristos    Written by Bruno Haible and Simon Josefsson.
4*946379e7Schristos 
5*946379e7Schristos    This program is free software; you can redistribute it and/or modify
6*946379e7Schristos    it under the terms of the GNU General Public License as published by
7*946379e7Schristos    the Free Software Foundation; either version 2, or (at your option)
8*946379e7Schristos    any later version.
9*946379e7Schristos 
10*946379e7Schristos    This program is distributed in the hope that it will be useful,
11*946379e7Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*946379e7Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*946379e7Schristos    GNU General Public License for more details.
14*946379e7Schristos 
15*946379e7Schristos    You should have received a copy of the GNU General Public License
16*946379e7Schristos    along with this program; if not, write to the Free Software Foundation,
17*946379e7Schristos    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18*946379e7Schristos 
19*946379e7Schristos #ifndef _STRICONV_H
20*946379e7Schristos #define _STRICONV_H
21*946379e7Schristos 
22*946379e7Schristos #include <stddef.h>
23*946379e7Schristos #if HAVE_ICONV
24*946379e7Schristos #include <iconv.h>
25*946379e7Schristos #endif
26*946379e7Schristos 
27*946379e7Schristos 
28*946379e7Schristos #ifdef __cplusplus
29*946379e7Schristos extern "C" {
30*946379e7Schristos #endif
31*946379e7Schristos 
32*946379e7Schristos 
33*946379e7Schristos #if HAVE_ICONV
34*946379e7Schristos 
35*946379e7Schristos /* Convert an entire string from one encoding to another, using iconv.
36*946379e7Schristos    The original string is at [SRC,...,SRC+SRCLEN-1].
37*946379e7Schristos    The conversion descriptor is passed as CD.
38*946379e7Schristos    *RESULTP should initially contain NULL or a malloced memory block.
39*946379e7Schristos    May change the size of the allocated memory block in *RESULTP, storing
40*946379e7Schristos    its new address in *RESULTP and its new length in *LENGTHP.
41*946379e7Schristos    Return value: 0 if successful, otherwise -1 and errno set.
42*946379e7Schristos    If successful, the resulting string is stored in *RESULTP and its length
43*946379e7Schristos    in *LENGTHP.  */
44*946379e7Schristos extern int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
45*946379e7Schristos 			 char **resultp, size_t *lengthp);
46*946379e7Schristos 
47*946379e7Schristos /* Convert an entire string from one encoding to another, using iconv.
48*946379e7Schristos    The original string is the NUL-terminated string starting at SRC.
49*946379e7Schristos    The conversion descriptor is passed as CD.  Both the "from" and the "to"
50*946379e7Schristos    encoding must use a single NUL byte at the end of the string (i.e. not
51*946379e7Schristos    UCS-2, UCS-4, UTF-16, UTF-32).
52*946379e7Schristos    Allocate a malloced memory block for the result.
53*946379e7Schristos    Return value: the freshly allocated resulting NUL-terminated string if
54*946379e7Schristos    successful, otherwise NULL and errno set.  */
55*946379e7Schristos extern char * str_cd_iconv (const char *src, iconv_t cd);
56*946379e7Schristos 
57*946379e7Schristos #endif
58*946379e7Schristos 
59*946379e7Schristos /* Convert an entire string from one encoding to another, using iconv.
60*946379e7Schristos    The original string is the NUL-terminated string starting at SRC.
61*946379e7Schristos    Both the "from" and the "to" encoding must use a single NUL byte at the
62*946379e7Schristos    end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
63*946379e7Schristos    Allocate a malloced memory block for the result.
64*946379e7Schristos    Return value: the freshly allocated resulting NUL-terminated string if
65*946379e7Schristos    successful, otherwise NULL and errno set.  */
66*946379e7Schristos extern char * str_iconv (const char *src,
67*946379e7Schristos 			 const char *from_codeset, const char *to_codeset);
68*946379e7Schristos 
69*946379e7Schristos 
70*946379e7Schristos #ifdef __cplusplus
71*946379e7Schristos }
72*946379e7Schristos #endif
73*946379e7Schristos 
74*946379e7Schristos 
75*946379e7Schristos #endif /* _STRICONV_H */
76