summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-12-20 12:23:51 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-12-21 21:24:36 +0330
commit0d7d2b825ef92111b2cf104e7c37ce14e941c5a0 (patch)
treec0af2eb82a71dfb8341c542bfa30db9b55022ec2 /Userland/Libraries/LibC
parent0fdf52f6dd001ec56a96fe3e21455f5e599ff3a1 (diff)
downloadserenity-0d7d2b825ef92111b2cf104e7c37ce14e941c5a0.zip
LibC: Add POSIX spec links to all applicable wide character functions
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/wchar.cpp40
-rw-r--r--Userland/Libraries/LibC/wstdio.cpp22
2 files changed, 62 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp
index 73a9833f3f..c2b74fae60 100644
--- a/Userland/Libraries/LibC/wchar.cpp
+++ b/Userland/Libraries/LibC/wchar.cpp
@@ -45,6 +45,7 @@ static unsigned int mbstate_expected_bytes(mbstate_t* state)
extern "C" {
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcslen.html
size_t wcslen(wchar_t const* str)
{
size_t len = 0;
@@ -53,6 +54,7 @@ size_t wcslen(wchar_t const* str)
return len;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcscpy.html
wchar_t* wcscpy(wchar_t* dest, wchar_t const* src)
{
wchar_t* original_dest = dest;
@@ -75,6 +77,7 @@ wchar_t* wcsdup(wchar_t const* str)
return wcscpy(new_str, str);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsncpy.html
wchar_t* wcsncpy(wchar_t* dest, wchar_t const* src, size_t num)
{
wchar_t* original_dest = dest;
@@ -95,6 +98,7 @@ size_t wcslcpy(wchar_t* dest, wchar_t const* src, size_t n)
return i;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcscmp.html
int wcscmp(wchar_t const* s1, wchar_t const* s2)
{
while (*s1 == *s2++)
@@ -103,6 +107,7 @@ int wcscmp(wchar_t const* s1, wchar_t const* s2)
return *(wchar_t const*)s1 - *(wchar_t const*)--s2;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsncmp.html
int wcsncmp(wchar_t const* s1, wchar_t const* s2, size_t n)
{
if (!n)
@@ -116,6 +121,7 @@ int wcsncmp(wchar_t const* s1, wchar_t const* s2, size_t n)
return 0;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcschr.html
wchar_t* wcschr(wchar_t const* str, int c)
{
wchar_t ch = c;
@@ -127,6 +133,7 @@ wchar_t* wcschr(wchar_t const* str, int c)
}
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsrchr.html
wchar_t* wcsrchr(wchar_t const* str, wchar_t wc)
{
wchar_t* last = nullptr;
@@ -138,6 +145,7 @@ wchar_t* wcsrchr(wchar_t const* str, wchar_t wc)
return last;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcscat.html
wchar_t* wcscat(wchar_t* dest, wchar_t const* src)
{
size_t dest_length = wcslen(dest);
@@ -148,6 +156,7 @@ wchar_t* wcscat(wchar_t* dest, wchar_t const* src)
return dest;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsncat.html
wchar_t* wcsncat(wchar_t* dest, wchar_t const* src, size_t n)
{
size_t dest_length = wcslen(dest);
@@ -158,6 +167,7 @@ wchar_t* wcsncat(wchar_t* dest, wchar_t const* src, size_t n)
return dest;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstok.html
wchar_t* wcstok(wchar_t* str, wchar_t const* delim, wchar_t** ptr)
{
wchar_t* used_str = str;
@@ -203,18 +213,21 @@ wchar_t* wcstok(wchar_t* str, wchar_t const* delim, wchar_t** ptr)
return &used_str[token_start];
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstol.html
long wcstol(wchar_t const*, wchar_t**, int)
{
dbgln("FIXME: Implement wcstol()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstoll.html
long long wcstoll(wchar_t const*, wchar_t**, int)
{
dbgln("FIXME: Implement wcstoll()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/btowc.html
wint_t btowc(int c)
{
if (c == EOF) {
@@ -229,6 +242,7 @@ wint_t btowc(int c)
return c;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrtowc.html
size_t mbrtowc(wchar_t* pwc, char const* s, size_t n, mbstate_t* state)
{
static mbstate_t _anonymous_state = {};
@@ -314,6 +328,7 @@ size_t mbrtowc(wchar_t* pwc, char const* s, size_t n, mbstate_t* state)
return consumed_bytes;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrlen.html
size_t mbrlen(char const* s, size_t n, mbstate_t* ps)
{
static mbstate_t anonymous_state = {};
@@ -324,6 +339,7 @@ size_t mbrlen(char const* s, size_t n, mbstate_t* ps)
return mbrtowc(nullptr, s, n, ps);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcrtomb.html
size_t wcrtomb(char* s, wchar_t wc, mbstate_t*)
{
if (s == nullptr)
@@ -342,6 +358,7 @@ size_t wcrtomb(char* s, wchar_t wc, mbstate_t*)
}
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcscoll.html
int wcscoll(wchar_t const* ws1, wchar_t const* ws2)
{
// TODO: Actually implement a sensible sort order for this,
@@ -349,12 +366,14 @@ int wcscoll(wchar_t const* ws1, wchar_t const* ws2)
return wcscmp(ws1, ws2);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsxfrm.html
size_t wcsxfrm(wchar_t* dest, wchar_t const* src, size_t n)
{
// TODO: This needs to be changed when wcscoll is not just doing wcscmp
return wcslcpy(dest, src, n);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wctob.html
int wctob(wint_t c)
{
if (c > 0x7f)
@@ -363,6 +382,7 @@ int wctob(wint_t c)
return static_cast<unsigned char>(c);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbsinit.html
int mbsinit(mbstate_t const* state)
{
if (!state) {
@@ -376,6 +396,7 @@ int mbsinit(mbstate_t const* state)
return 1;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcspbrk.html
wchar_t* wcspbrk(wchar_t const* wcs, wchar_t const* accept)
{
for (wchar_t const* cur = accept; *cur; cur++) {
@@ -387,6 +408,7 @@ wchar_t* wcspbrk(wchar_t const* wcs, wchar_t const* accept)
return nullptr;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsstr.html
wchar_t* wcsstr(wchar_t const* haystack, wchar_t const* needle)
{
size_t nlen = wcslen(needle);
@@ -407,6 +429,7 @@ wchar_t* wcsstr(wchar_t const* haystack, wchar_t const* needle)
return nullptr;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wmemchr.html
wchar_t* wmemchr(wchar_t const* s, wchar_t c, size_t n)
{
for (size_t i = 0; i < n; i++) {
@@ -417,6 +440,7 @@ wchar_t* wmemchr(wchar_t const* s, wchar_t c, size_t n)
return nullptr;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wmemcpy.html
wchar_t* wmemcpy(wchar_t* dest, wchar_t const* src, size_t n)
{
for (size_t i = 0; i < n; i++)
@@ -425,6 +449,7 @@ wchar_t* wmemcpy(wchar_t* dest, wchar_t const* src, size_t n)
return dest;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wmemset.html
wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t n)
{
for (size_t i = 0; i < n; i++) {
@@ -434,6 +459,7 @@ wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t n)
return wcs;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wmemmove.html
wchar_t* wmemmove(wchar_t* dest, wchar_t const* src, size_t n)
{
if (dest > src) {
@@ -449,36 +475,42 @@ wchar_t* wmemmove(wchar_t* dest, wchar_t const* src, size_t n)
return dest;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstoul.html
unsigned long wcstoul(wchar_t const*, wchar_t**, int)
{
dbgln("TODO: Implement wcstoul()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstoull.html
unsigned long long wcstoull(wchar_t const*, wchar_t**, int)
{
dbgln("TODO: Implement wcstoull()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstof.html
float wcstof(wchar_t const*, wchar_t**)
{
dbgln("TODO: Implement wcstof()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstod.html
double wcstod(wchar_t const*, wchar_t**)
{
dbgln("TODO: Implement wcstod()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcstold.html
long double wcstold(wchar_t const*, wchar_t**)
{
dbgln("TODO: Implement wcstold()");
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcwidth.html
int wcwidth(wchar_t wc)
{
if (wc == L'\0')
@@ -496,6 +528,7 @@ int wcwidth(wchar_t wc)
return 1;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsnrtombs.html
size_t wcsnrtombs(char* dest, wchar_t const** src, size_t nwc, size_t len, mbstate_t* ps)
{
static mbstate_t _anonymous_state = {};
@@ -542,6 +575,7 @@ size_t wcsnrtombs(char* dest, wchar_t const** src, size_t nwc, size_t len, mbsta
return written;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbsnrtowcs.html
size_t mbsnrtowcs(wchar_t* dst, char const** src, size_t nms, size_t len, mbstate_t* ps)
{
static mbstate_t _anonymous_state = {};
@@ -590,6 +624,7 @@ size_t mbsnrtowcs(wchar_t* dst, char const** src, size_t nms, size_t len, mbstat
return written;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wmemcmp.html
int wmemcmp(wchar_t const* s1, wchar_t const* s2, size_t n)
{
while (n-- > 0) {
@@ -599,6 +634,7 @@ int wmemcmp(wchar_t const* s1, wchar_t const* s2, size_t n)
return 0;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsrtombs.html
size_t wcsrtombs(char* dest, wchar_t const** src, size_t len, mbstate_t* ps)
{
static mbstate_t anonymous_state = {};
@@ -610,6 +646,7 @@ size_t wcsrtombs(char* dest, wchar_t const** src, size_t len, mbstate_t* ps)
return wcsnrtombs(dest, src, SIZE_MAX, len, ps);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbsrtowcs.html
size_t mbsrtowcs(wchar_t* dst, char const** src, size_t len, mbstate_t* ps)
{
static mbstate_t anonymous_state = {};
@@ -621,6 +658,7 @@ size_t mbsrtowcs(wchar_t* dst, char const** src, size_t len, mbstate_t* ps)
return mbsnrtowcs(dst, src, SIZE_MAX, len, ps);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcscspn.html
size_t wcscspn(wchar_t const* wcs, wchar_t const* reject)
{
for (auto const* wc_pointer = wcs;;) {
@@ -634,6 +672,7 @@ size_t wcscspn(wchar_t const* wcs, wchar_t const* reject)
}
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsspn.html
size_t wcsspn(wchar_t const* wcs, wchar_t const* accept)
{
for (auto const* wc_pointer = wcs;;) {
@@ -647,6 +686,7 @@ size_t wcsspn(wchar_t const* wcs, wchar_t const* accept)
}
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html
size_t wcsftime(wchar_t* __restrict wcs, size_t maxsize, wchar_t const* __restrict format, const struct tm* __restrict timeptr)
{
(void)wcs;
diff --git a/Userland/Libraries/LibC/wstdio.cpp b/Userland/Libraries/LibC/wstdio.cpp
index 7e872491d9..041afece5f 100644
--- a/Userland/Libraries/LibC/wstdio.cpp
+++ b/Userland/Libraries/LibC/wstdio.cpp
@@ -18,12 +18,14 @@ static_assert(AssertSize<wchar_t, sizeof(u32)>());
extern "C" {
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwide.html
int fwide(FILE*, int mode)
{
// Nope Nope Nope.
return mode;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetwc.html
wint_t fgetwc(FILE* stream)
{
VERIFY(stream);
@@ -60,16 +62,19 @@ wint_t fgetwc(FILE* stream)
return code_point;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/getwc.html
wint_t getwc(FILE* stream)
{
return fgetwc(stream);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/getwchar.html
wint_t getwchar()
{
return getwc(stdin);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputwc.html
wint_t fputwc(wchar_t wc, FILE* stream)
{
VERIFY(stream);
@@ -90,16 +95,19 @@ wint_t fputwc(wchar_t wc, FILE* stream)
return wc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/putwc.html
wint_t putwc(wchar_t wc, FILE* stream)
{
return fputwc(wc, stream);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/putwchar.html
wint_t putwchar(wchar_t wc)
{
return fputwc(wc, stdout);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetws.html
wchar_t* fgetws(wchar_t* __restrict buffer, int size, FILE* __restrict stream)
{
VERIFY(stream);
@@ -108,6 +116,7 @@ wchar_t* fgetws(wchar_t* __restrict buffer, int size, FILE* __restrict stream)
return ok ? buffer : nullptr;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputws.html
int fputws(wchar_t const* __restrict ws, FILE* __restrict stream)
{
VERIFY(stream);
@@ -120,6 +129,7 @@ int fputws(wchar_t const* __restrict ws, FILE* __restrict stream)
return size;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ungetwc.html
wint_t ungetwc(wint_t wc, FILE* stream)
{
VERIFY(stream);
@@ -139,6 +149,7 @@ wint_t ungetwc(wint_t wc, FILE* stream)
return wc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wprintf.html
int wprintf(wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -148,6 +159,7 @@ int wprintf(wchar_t const* __restrict format, ...)
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwprintf.html
int fwprintf(FILE* __restrict stream, wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -157,6 +169,7 @@ int fwprintf(FILE* __restrict stream, wchar_t const* __restrict format, ...)
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/swprintf.html
int swprintf(wchar_t* __restrict wcs, size_t max_length, wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -166,11 +179,13 @@ int swprintf(wchar_t* __restrict wcs, size_t max_length, wchar_t const* __restri
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vwprintf.html
int vwprintf(wchar_t const* __restrict format, va_list args)
{
return vfwprintf(stdout, format, args);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vfwprintf.html
int vfwprintf(FILE* __restrict stream, wchar_t const* __restrict format, va_list args)
{
auto const* fmt = bit_cast<wchar_t const*>(format);
@@ -180,6 +195,7 @@ int vfwprintf(FILE* __restrict stream, wchar_t const* __restrict format, va_list
nullptr, fmt, args);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vswprintf.html
int vswprintf(wchar_t* __restrict wcs, size_t max_length, wchar_t const* __restrict format, va_list args)
{
auto const* fmt = bit_cast<wchar_t const*>(format);
@@ -194,6 +210,7 @@ int vswprintf(wchar_t* __restrict wcs, size_t max_length, wchar_t const* __restr
return static_cast<int>(length_so_far);
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwscanf.html
int fwscanf(FILE* __restrict stream, wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -203,6 +220,7 @@ int fwscanf(FILE* __restrict stream, wchar_t const* __restrict format, ...)
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/swscanf.html
int swscanf(wchar_t const* __restrict ws, wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -212,6 +230,7 @@ int swscanf(wchar_t const* __restrict ws, wchar_t const* __restrict format, ...)
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wscanf.html
int wscanf(wchar_t const* __restrict format, ...)
{
va_list ap;
@@ -221,6 +240,7 @@ int wscanf(wchar_t const* __restrict format, ...)
return rc;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vfwscanf.html
int vfwscanf(FILE* __restrict stream, wchar_t const* __restrict format, va_list arg)
{
(void)stream;
@@ -230,6 +250,7 @@ int vfwscanf(FILE* __restrict stream, wchar_t const* __restrict format, va_list
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vswscanf.html
int vswscanf(wchar_t const* __restrict ws, wchar_t const* __restrict format, va_list arg)
{
(void)ws;
@@ -239,6 +260,7 @@ int vswscanf(wchar_t const* __restrict ws, wchar_t const* __restrict format, va_
TODO();
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/vwscanf.html
int vwscanf(wchar_t const* __restrict format, va_list arg)
{
(void)format;