summaryrefslogtreecommitdiff
path: root/libgcompat/wchar.c
diff options
context:
space:
mode:
authorLassebq <lassebq.mine@gmail.com>2024-05-10 22:19:35 +0300
committerAnna Wilcox <awilcox@wilcox-tech.com>2024-10-22 18:51:15 +0000
commit7f2d3d5a82db83a34d5947d6bd195d81e1fc2b9b (patch)
tree51c75d120780e03595b12b0fa4eec72d1b42b322 /libgcompat/wchar.c
parent785d71e5ba6498e38e974080c99ed853923ba815 (diff)
downloadgcompat-7f2d3d5a82db83a34d5947d6bd195d81e1fc2b9b.tar.gz
gcompat-7f2d3d5a82db83a34d5947d6bd195d81e1fc2b9b.tar.bz2
gcompat-7f2d3d5a82db83a34d5947d6bd195d81e1fc2b9b.tar.xz
gcompat-7f2d3d5a82db83a34d5947d6bd195d81e1fc2b9b.zip
wchar: add __wcscat_chk, __wcsncpy_chkHEADcurrent
Diffstat (limited to 'libgcompat/wchar.c')
-rw-r--r--libgcompat/wchar.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/libgcompat/wchar.c b/libgcompat/wchar.c
index 78f7e02..4af686d 100644
--- a/libgcompat/wchar.c
+++ b/libgcompat/wchar.c
@@ -109,8 +109,8 @@ long int __wcstol_internal(const wchar_t *nptr, wchar_t **endptr, int base,
*
* Some day, when musl supports LC_NUMERIC, we can probably remove this.
*/
-unsigned long int wcstoul_l(const wchar_t *nptr, wchar_t **endptr,
- int base, locale_t loc)
+unsigned long int wcstoul_l(const wchar_t *nptr, wchar_t **endptr, int base,
+ locale_t loc)
{
return wcstoul(nptr, endptr, base);
}
@@ -120,8 +120,7 @@ unsigned long int wcstoul_l(const wchar_t *nptr, wchar_t **endptr,
*
* Some day, when musl supports LC_NUMERIC, we can probably remove this.
*/
-long int wcstol_l(const wchar_t *nptr, wchar_t **endptr, int base,
- locale_t loc)
+long int wcstol_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t loc)
{
return wcstol(nptr, endptr, base);
}
@@ -136,7 +135,33 @@ double wcstod_l(const wchar_t *nptr, wchar_t **endptr, locale_t loc)
return wcstod(nptr, endptr);
}
+size_t __mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st)
+{
+ return mbrlen(s, n, st);
+}
+
+wchar_t *__wcsncpy_chk(wchar_t *dest, const wchar_t *src, size_t n,
+ size_t destlen)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
-size_t __mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st) {
- return mbrlen(s, n, st);
+ assert(destlen >= n);
+
+ return wcsncpy(dest, src, n);
+}
+
+wchar_t *__wcscat_chk(wchar_t *dest, const wchar_t *src, size_t n)
+{
+ wchar_t *a = dest;
+ size_t destlen = wcslen(dest);
+ assert(destlen + wcslen(src) + 1 <= n);
+
+ dest += destlen;
+ while (n && *src) {
+ n--;
+ *dest++ = *src++;
+ }
+ *dest++ = 0;
+ return a;
}