openat: don’t close (-1)
[gnulib.git] / lib / unicodeio.h
blob0db1d35f52b42ba7e102336cfe3e9a9b1de6ec5b
1 /* Unicode character output to streams with locale dependent encoding.
3 Copyright (C) 2000-2003, 2005, 2008-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef UNICODEIO_H
19 #define UNICODEIO_H
21 #include <stddef.h>
22 #include <stdio.h>
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
29 /* Converts the Unicode character CODE to its multibyte representation
30 in the current locale and calls the SUCCESS callback on the resulting
31 byte sequence. If an error occurs, invokes the FAILURE callback instead,
32 passing it CODE and an English error string.
33 Returns whatever the callback returned.
34 Assumes that the locale doesn't change between two calls. */
35 extern long unicode_to_mb (unsigned int code,
36 long (*success) (const char *buf, size_t buflen,
37 void *callback_arg),
38 long (*failure) (unsigned int code, const char *msg,
39 void *callback_arg),
40 void *callback_arg);
42 /* Outputs the Unicode character CODE to the output stream STREAM.
43 Upon failure, exit if exit_on_error is true, otherwise output a fallback
44 notation. */
45 extern void print_unicode_char (FILE *stream, unsigned int code,
46 int exit_on_error);
48 /* Simple success callback that outputs the converted string.
49 The STREAM is passed as callback_arg. */
50 extern long fwrite_success_callback (const char *buf, size_t buflen,
51 void *callback_arg);
54 #ifdef __cplusplus
56 #endif
58 #endif