source: mainline/common/include/wchar.h

Last change on this file was 696b405, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 months ago

Implement standard character conversion functions from <uchar.h> and <wchar.h>

These are more somewhat more flexible than the existing functions in <str.h> since
they can process incomplete stream and save unfinished character for next call.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Copyright (c) 2025 Jiří Zárevúcky
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef _LIBC_WCHAR_H_
30#define _LIBC_WCHAR_H_
31
32#include <_bits/NULL.h>
33#include <_bits/WEOF.h>
34#include <_bits/mbstate_t.h>
35#include <_bits/size_t.h>
36#include <_bits/wchar_limits.h>
37#include <_bits/wchar_t.h>
38#include <_bits/wint_t.h>
39#include <stdarg.h>
40
41/* Forward declarations for types. */
42typedef struct _IO_FILE FILE;
43struct tm;
44
45/*
46 * Complete list of functions straight out of ISO/IEC 9899:2023 (N3096 draft).
47 * Only some of these are implemented, but keep all standard prototypes here
48 * for less pain in libposix etc.
49 */
50
51int fputws(const wchar_t *__restrict__, FILE *__restrict__);
52int fwide(FILE *, int mode);
53int fwprintf(FILE *__restrict__, const wchar_t *__restrict__, ...);
54int fwscanf(FILE *__restrict__, const wchar_t *__restrict__, ...);
55int mbsinit(const mbstate_t *);
56int swprintf(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, ...);
57int swscanf(const wchar_t *__restrict__, const wchar_t *__restrict__, ...);
58int vfwprintf(FILE *__restrict__, const wchar_t *__restrict__, va_list);
59int vfwscanf(FILE *__restrict__, const wchar_t *__restrict__, va_list);
60int vswprintf(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list);
61int vswscanf(const wchar_t *__restrict__, const wchar_t *__restrict__, va_list);
62int vwprintf(const wchar_t *__restrict__, va_list);
63int vwscanf(const wchar_t *__restrict__, va_list);
64int wcscmp(const wchar_t *, const wchar_t *);
65int wcscoll(const wchar_t *, const wchar_t *);
66int wcsncmp(const wchar_t *, const wchar_t *, size_t);
67int wctob(wint_t);
68int wmemcmp(const wchar_t *, const wchar_t *, size_t);
69int wprintf(const wchar_t *__restrict__, ...);
70int wscanf(const wchar_t *__restrict__, ...);
71long int wcstol(const wchar_t *__restrict__, wchar_t **__restrict__, int);
72long long int wcstoll(const wchar_t *__restrict__, wchar_t **__restrict__, int);
73size_t mbrlen(const char *__restrict__, size_t, mbstate_t *__restrict__);
74size_t mbrtowc(wchar_t *__restrict__ pwc, const char *__restrict__, size_t, mbstate_t *__restrict__);
75size_t mbsrtowcs(wchar_t *__restrict__ dst, const char **__restrict__ src, size_t, mbstate_t *__restrict__);
76size_t wcrtomb(char *__restrict__, wchar_t wc, mbstate_t *__restrict__);
77size_t wcscspn(const wchar_t *, const wchar_t *);
78size_t wcsftime(wchar_t *__restrict__, size_t maxsize, const wchar_t *__restrict__, const struct tm *__restrict__ timeptr);
79size_t wcslen(const wchar_t *);
80size_t wcsrtombs(char *__restrict__ dst, const wchar_t **__restrict__ src, size_t, mbstate_t *__restrict__);
81size_t wcsspn(const wchar_t *, const wchar_t *);
82size_t wcsxfrm(wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
83unsigned long int wcstoul(const wchar_t *__restrict__, wchar_t **__restrict__, int);
84unsigned long long int wcstoull(const wchar_t *__restrict__, wchar_t **__restrict__, int);
85wchar_t *fgetws(wchar_t *__restrict__, int, FILE *__restrict__);
86wchar_t *wcscat(wchar_t *__restrict__, const wchar_t *__restrict__);
87wchar_t *wcscpy(wchar_t *__restrict__, const wchar_t *__restrict__);
88wchar_t *wcsncat(wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
89wchar_t *wcsncpy(wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
90wchar_t *wcstok(wchar_t *__restrict__, const wchar_t *__restrict__, wchar_t **__restrict__);
91wchar_t *wmemcpy(wchar_t *__restrict__, const wchar_t *__restrict__, size_t);
92wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t);
93wchar_t *wmemset(wchar_t *, wchar_t, size_t);
94wint_t btowc(int);
95wint_t fgetwc(FILE *);
96wint_t fputwc(wchar_t, FILE *);
97wint_t getwc(FILE *);
98wint_t getwchar(void);
99wint_t putwc(wchar_t, FILE *);
100wint_t putwchar(wchar_t);
101wint_t ungetwc(wint_t, FILE *);
102
103// TODO: In C23, these functions have generic macro definitions for correct
104// const handling.
105wchar_t *wcschr(const wchar_t *, wchar_t);
106wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
107wchar_t *wcsrchr(const wchar_t *, wchar_t);
108wchar_t *wcsstr(const wchar_t *, const wchar_t *);
109wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
110
111#endif /* _LIBC_WCHAR_H_ */
Note: See TracBrowser for help on using the repository browser.