Elliott Hughes | a648733 | 2017-08-15 23:16:48 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file iconv.h |
| 33 | * @brief Character encoding conversion. |
| 34 | */ |
Elliott Hughes | a648733 | 2017-08-15 23:16:48 -0700 | [diff] [blame] | 35 | |
| 36 | #include <sys/cdefs.h> |
| 37 | #include <sys/types.h> |
| 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 41 | /* If we just use void* in the typedef, the compiler exposes that in error messages. */ |
Elliott Hughes | a648733 | 2017-08-15 23:16:48 -0700 | [diff] [blame] | 42 | struct __iconv_t; |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * The `iconv_t` type that represents an instance of a converter. |
| 46 | */ |
Elliott Hughes | a648733 | 2017-08-15 23:16:48 -0700 | [diff] [blame] | 47 | typedef struct __iconv_t* iconv_t; |
| 48 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 49 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 50 | * [iconv_open(3)](https://man7.org/linux/man-pages/man3/iconv_open.3.html) allocates a new converter |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 51 | * from `__src_encoding` to `__dst_encoding`. |
| 52 | * |
Elliott Hughes | bac2573 | 2023-06-14 20:55:58 +0000 | [diff] [blame] | 53 | * 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 Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 59 | * 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 Hughes | 7a5d992 | 2023-06-13 07:37:28 -0700 | [diff] [blame] | 63 | iconv_t _Nonnull iconv_open(const char* _Nonnull __dst_encoding, const char* _Nonnull __src_encoding) __INTRODUCED_IN(28); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 66 | * [iconv(3)](https://man7.org/linux/man-pages/man3/iconv.3.html) converts characters from one |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 67 | * encoding to another. |
| 68 | * |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 69 | * 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 | */ |
zijunzhao | 32b6d43 | 2023-02-24 02:32:35 +0000 | [diff] [blame] | 74 | size_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 Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 77 | * [iconv_close(3)](https://man7.org/linux/man-pages/man3/iconv_close.3.html) deallocates a converter |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 78 | * 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 | */ |
zijunzhao | 32b6d43 | 2023-02-24 02:32:35 +0000 | [diff] [blame] | 84 | int iconv_close(iconv_t _Nonnull __converter) __INTRODUCED_IN(28); |
Elliott Hughes | a648733 | 2017-08-15 23:16:48 -0700 | [diff] [blame] | 85 | |
| 86 | __END_DECLS |