some wchar stuff

This commit is contained in:
bumbread 2022-08-05 15:00:54 +11:00
parent cc3f1eba1b
commit 97c201b96f
6 changed files with 101 additions and 7 deletions

View File

@ -1,4 +0,0 @@
nasm src\_win\chkstk.asm -ochkstk.o -fwin64
cl src\ciabatta.c -c -DCIABATTA_WIN -I inc -I src\_win /Z7 /showIncludes /arch:sse2
lib /nologo /out:ciabatta.lib chkstk.o ciabatta.obj src\fdec64\fdec64.lib src\unicope\unicope.lib

View File

@ -5,7 +5,7 @@
#define __func__ __FUNCTION__
#endif
#if defined (_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
#define _Noreturn
#endif

View File

@ -1,6 +1,6 @@
#pragma once
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
#define _Noreturn __declspec(noreturn)
#endif

View File

@ -58,6 +58,7 @@
#include "locale.c"
#include "string.c"
#include "uchar.c"
#include "wchar.c"
#include "wctype.c"
// Windows stuff

View File

@ -14,7 +14,7 @@ void *memcpy(void *restrict s1, const void *restrict s2, size_t n) {
void *memmove(void *s1, const void *s2, size_t n) {
byte* c1 = s1;
const byte* c2 = s2;
// Note(bumbread): shouldn't this be backwards?
if (c1 != c2) {
if (c1 < c2) {
// reverse copy

97
src/wchar.c Normal file
View File

@ -0,0 +1,97 @@
size_t wcslen(const wchar_t *s) {
size_t len = 0;
while(s[len++]);
return len;
}
wchar_t *wmemset(wchar_t *str, wchar_t c, size_t n) {
while(n--) {
str[n] = c;
}
return str;
}
wchar_t *wmemmove(wchar_t *dst, wchar_t const *src, size_t n) {
if(dst != src) {
if(dst < src) {
for (size_t i = n; i--;) dst[i] = src[i];
} else {
for (size_t i = 0; i < n; i++) dst[i] = src[i];
}
}
return dst;
}
wchar_t *wmemcpy(wchar_t *restrict dst, wchar_t const *restrict src, size_t n) {
while(n--) dst[n] = src[n];
return (wchar_t *)dst;
}
wchar_t *wcscpy(wchar_t *restrict dst, wchar_t const *restrict src) {
size_t i;
for(i = 0; src[i]; ++i) {
dst[i] = src[i];
}
dst[i] = 0;
return (wchar_t *)dst;
}
wchar_t *wcsncpy(wchar_t *restrict dst, wchar_t const *restrict src, size_t n) {
size_t i;
for(i = 0; i != n && src[i]; ++i) {
dst[i] = src[i];
}
dst[i] = 0;
return (wchar_t *)dst;
}
wchar_t *wcscat(wchar_t *restrict dst, wchar_t const *restrict src) {
size_t dst_len = wcslen(dst);
size_t i;
for(i = 0; src[i]; ++i) {
dst[dst_len + i] = src[i];
}
dst[dst_len + i] = 0;
return (wchar_t *)dst;
}
wchar_t *wcsncat(wchar_t *restrict dst, wchar_t const *restrict src, size_t n) {
size_t dst_len = wcslen(dst);
size_t i;
for(i = 0; i != n && src[i]; ++i) {
dst[dst_len + i] = src[i];
}
dst[dst_len + i] = 0;
return (wchar_t *)dst;
}
int wcscmp(wchar_t const *s1, wchar_t const *s2) {
size_t i;
for(i = 0; s1[i] && s2[i]; ++i) {
if(s1[i] != s2[i]) break;
}
if(s1[i] < s2[i]) return -1;
if(s1[i] > s2[i]) return 1;
return 0;
}
int wcsncmp(wchar_t const *s1, wchar_t const *s2, size_t n) {
size_t i;
for(i = 0; i != n && s1[i] && s2[i]; ++i) {
if(s1[i] != s2[i]) break;
}
if(s1[i] < s2[i]) return -1;
if(s1[i] > s2[i]) return 1;
return 0;
}
int wmemcmp(wchar_t const *s1, wchar_t const *s2, size_t n) {
size_t i;
for(i = 0; i != n; ++i) {
if(s1[i] != s2[i]) break;
}
if(s1[i] < s2[i]) return -1;
if(s1[i] > s2[i]) return 1;
return 0;
}