blob: ec4bdeafef84f4a949b1a4b8991f359777ba3b53 [file] [log] [blame]
Elliott Hughesa6487332017-08-15 23:16:48 -07001/*
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
Elliott Hughes462e90c2018-08-21 16:10:48 -070029#pragma once
30
31/**
32 * @file iconv.h
33 * @brief Character encoding conversion.
34 */
Elliott Hughesa6487332017-08-15 23:16:48 -070035
36#include <sys/cdefs.h>
37#include <sys/types.h>
38
39__BEGIN_DECLS
40
Elliott Hughes462e90c2018-08-21 16:10:48 -070041/* If we just use void* in the typedef, the compiler exposes that in error messages. */
Elliott Hughesa6487332017-08-15 23:16:48 -070042struct __iconv_t;
Elliott Hughes462e90c2018-08-21 16:10:48 -070043
44/**
45 * The `iconv_t` type that represents an instance of a converter.
46 */
Elliott Hughesa6487332017-08-15 23:16:48 -070047typedef struct __iconv_t* iconv_t;
48
Elliott Hughes462e90c2018-08-21 16:10:48 -070049/**
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 */
Elliott Hughescc0fe6e2018-01-30 08:54:12 -080057iconv_t iconv_open(const char* __src_encoding, const char* __dst_encoding) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070058
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 */
Elliott Hughescc0fe6e2018-01-30 08:54:12 -080071size_t iconv(iconv_t __converter, char** __src_buf, size_t* __src_bytes_left, char** __dst_buf, size_t* __dst_bytes_left) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070072
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 */
Elliott Hughescc0fe6e2018-01-30 08:54:12 -080081int iconv_close(iconv_t __converter) __INTRODUCED_IN(28);
Elliott Hughesa6487332017-08-15 23:16:48 -070082
83__END_DECLS