xref: /aosp_15_r20/external/flac/src/share/utf8/iconvert.h (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li /*
2*600f14f4SXin Li  * Copyright (C) 2001 Edmund Grimley Evans <[email protected]>
3*600f14f4SXin Li  *
4*600f14f4SXin Li  * This program is free software; you can redistribute it and/or modify
5*600f14f4SXin Li  * it under the terms of the GNU General Public License as published by
6*600f14f4SXin Li  * the Free Software Foundation; either version 2 of the License, or
7*600f14f4SXin Li  * (at your option) any later version.
8*600f14f4SXin Li  *
9*600f14f4SXin Li  * This program is distributed in the hope that it will be useful,
10*600f14f4SXin Li  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*600f14f4SXin Li  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*600f14f4SXin Li  * GNU General Public License for more details.
13*600f14f4SXin Li  *
14*600f14f4SXin Li  * You should have received a copy of the GNU General Public License along
15*600f14f4SXin Li  * with this program; if not, write to the Free Software Foundation, Inc.,
16*600f14f4SXin Li  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17*600f14f4SXin Li  */
18*600f14f4SXin Li 
19*600f14f4SXin Li #ifdef HAVE_CONFIG_H
20*600f14f4SXin Li #  include <config.h>
21*600f14f4SXin Li #endif
22*600f14f4SXin Li 
23*600f14f4SXin Li #ifdef HAVE_ICONV
24*600f14f4SXin Li 
25*600f14f4SXin Li /*
26*600f14f4SXin Li  * Convert data from one encoding to another. Return:
27*600f14f4SXin Li  *
28*600f14f4SXin Li  *  -2 : memory allocation failed
29*600f14f4SXin Li  *  -1 : unknown encoding
30*600f14f4SXin Li  *   0 : data was converted exactly
31*600f14f4SXin Li  *   1 : data was converted inexactly
32*600f14f4SXin Li  *   2 : data was invalid (but still converted)
33*600f14f4SXin Li  *
34*600f14f4SXin Li  * We convert in two steps, via UTF-8, as this is the only
35*600f14f4SXin Li  * reliable way of distinguishing between invalid input
36*600f14f4SXin Li  * and valid input which iconv refuses to transliterate.
37*600f14f4SXin Li  * We convert from UTF-8 twice, because we have no way of
38*600f14f4SXin Li  * knowing whether the conversion was exact if iconv returns
39*600f14f4SXin Li  * E2BIG (due to a bug in the specification of iconv).
40*600f14f4SXin Li  * An alternative approach is to assume that the output of
41*600f14f4SXin Li  * iconv is never more than 4 times as long as the input,
42*600f14f4SXin Li  * but I prefer to avoid that assumption if possible.
43*600f14f4SXin Li  */
44*600f14f4SXin Li 
45*600f14f4SXin Li int iconvert(const char *fromcode, const char *tocode,
46*600f14f4SXin Li 	     const char *from, size_t fromlen,
47*600f14f4SXin Li 	     char **to, size_t *tolen) ;
48*600f14f4SXin Li 
49*600f14f4SXin Li #endif /* HAVE_ICONV */
50