• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 /**
32  * @file iconv.h
33  * @brief Character encoding conversion.
34  */
35 
36 #include <sys/cdefs.h>
37 #include <sys/types.h>
38 
39 __BEGIN_DECLS
40 
41 /* If we just use void* in the typedef, the compiler exposes that in error messages. */
42 struct __iconv_t;
43 
44 /**
45  * The `iconv_t` type that represents an instance of a converter.
46  */
47 typedef struct __iconv_t* iconv_t;
48 
49 /**
50  * [iconv_open(3)](http://man7.org/linux/man-pages/man3/iconv_open.3.html) allocates a new converter
51  * from `__src_encoding` to `__dst_encoding`.
52  *
53  * Returns a new `iconv_t` on success and returns `((iconv_t) -1)` and sets `errno` on failure.
54  *
55  * Available since API level 28.
56  */
57 iconv_t iconv_open(const char* __src_encoding, const char* __dst_encoding) __INTRODUCED_IN(28);
58 
59 /**
60  * [iconv(3)](http://man7.org/linux/man-pages/man3/iconv.3.html) converts characters from one
61  * encoding to another.
62  *
63  * Android supports the `utf8`, `ascii`, `usascii`, `utf16be`, `utf16le`, `utf32be`, `utf32le`,
64  * and `wchart` encodings. Android also supports the GNU `//IGNORE` and `//TRANSLIT` extensions.
65  *
66  * Returns the number of characters converted on success and returns `((size_t) -1)` and
67  * sets `errno` on failure.
68  *
69  * Available since API level 28.
70  */
71 size_t iconv(iconv_t __converter, char** __src_buf, size_t* __src_bytes_left, char** __dst_buf, size_t* __dst_bytes_left) __INTRODUCED_IN(28);
72 
73 /**
74  * [iconv_close(3)](http://man7.org/linux/man-pages/man3/iconv_close.3.html) deallocates a converter
75  * returned by iconv_open().
76  *
77  * Returns 0 on success and returns -1 and sets `errno` on failure.
78  *
79  * Available since API level 28.
80  */
81 int iconv_close(iconv_t __converter) __INTRODUCED_IN(28);
82 
83 __END_DECLS
84