blob: 9da46b4ef410fe7650f6e659cb5b86313ed8a8d2 [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/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000050 * [iconv_open(3)](https://man7.org/linux/man-pages/man3/iconv_open.3.html) allocates a new converter
Elliott Hughes462e90c2018-08-21 16:10:48 -070051 * from `__src_encoding` to `__dst_encoding`.
52 *
Elliott Hughesbac25732023-06-14 20:55:58 +000053 * Android supports the `utf8`, `ascii`, `usascii`, `utf16be`, `utf16le`, `utf32be`, `utf32le`,
54 * and `wchart` encodings for both source and destination.
55 *
56 * Android supports the GNU `//IGNORE` and `//TRANSLIT` extensions for the
57 * destination encoding.
58 *
Elliott Hughes462e90c2018-08-21 16:10:48 -070059 * Returns a new `iconv_t` on success and returns `((iconv_t) -1)` and sets `errno` on failure.
60 *
61 * Available since API level 28.
62 */
Elliott Hughes7a5d9922023-06-13 07:37:28 -070063iconv_t _Nonnull iconv_open(const char* _Nonnull __dst_encoding, const char* _Nonnull __src_encoding) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070064
65/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000066 * [iconv(3)](https://man7.org/linux/man-pages/man3/iconv.3.html) converts characters from one
Elliott Hughes462e90c2018-08-21 16:10:48 -070067 * encoding to another.
68 *
Elliott Hughes462e90c2018-08-21 16:10:48 -070069 * Returns the number of characters converted on success and returns `((size_t) -1)` and
70 * sets `errno` on failure.
71 *
72 * Available since API level 28.
73 */
zijunzhao32b6d432023-02-24 02:32:35 +000074size_t iconv(iconv_t _Nonnull __converter, char* _Nullable * _Nullable __src_buf, size_t* __BIONIC_COMPLICATED_NULLNESS __src_bytes_left, char* _Nullable * _Nullable __dst_buf, size_t* __BIONIC_COMPLICATED_NULLNESS __dst_bytes_left) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070075
76/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000077 * [iconv_close(3)](https://man7.org/linux/man-pages/man3/iconv_close.3.html) deallocates a converter
Elliott Hughes462e90c2018-08-21 16:10:48 -070078 * returned by iconv_open().
79 *
80 * Returns 0 on success and returns -1 and sets `errno` on failure.
81 *
82 * Available since API level 28.
83 */
zijunzhao32b6d432023-02-24 02:32:35 +000084int iconv_close(iconv_t _Nonnull __converter) __INTRODUCED_IN(28);
Elliott Hughesa6487332017-08-15 23:16:48 -070085
86__END_DECLS