ALOT OF CHANGES
This commit is contained in:
@@ -39,8 +39,8 @@ OS_API bool OS_IsAbsolute(S8_String path) {
|
||||
}
|
||||
|
||||
OS_API S8_String OS_GetExePath(MA_Arena *arena) {
|
||||
wchar_t wbuffer[1024];
|
||||
DWORD wsize = GetModuleFileNameW(0, wbuffer, MA_Lengthof(wbuffer));
|
||||
char16_t wbuffer[1024];
|
||||
DWORD wsize = GetModuleFileNameW(0, (wchar_t *)wbuffer, MA_Lengthof(wbuffer));
|
||||
IO_Assert(wsize != 0);
|
||||
|
||||
S8_String path = S8_FromWidecharEx(arena, wbuffer, wsize);
|
||||
@@ -58,8 +58,8 @@ OS_API S8_String OS_GetExeDir(MA_Arena *arena) {
|
||||
}
|
||||
|
||||
OS_API S8_String OS_GetWorkingDir(MA_Arena *arena) {
|
||||
wchar_t wbuffer[1024];
|
||||
DWORD wsize = GetCurrentDirectoryW(MA_Lengthof(wbuffer), wbuffer);
|
||||
char16_t wbuffer[1024];
|
||||
DWORD wsize = GetCurrentDirectoryW(MA_Lengthof(wbuffer), (wchar_t *)wbuffer);
|
||||
IO_Assert(wsize != 0);
|
||||
IO_Assert(wsize < 1022);
|
||||
wbuffer[wsize++] = '/';
|
||||
@@ -71,16 +71,16 @@ OS_API S8_String OS_GetWorkingDir(MA_Arena *arena) {
|
||||
}
|
||||
|
||||
OS_API void OS_SetWorkingDir(S8_String path) {
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), path.str, path.len);
|
||||
SetCurrentDirectoryW(wpath);
|
||||
SetCurrentDirectoryW((wchar_t *)wpath);
|
||||
}
|
||||
|
||||
OS_API S8_String OS_GetAbsolutePath(MA_Arena *arena, S8_String relative) {
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), relative.str, relative.len);
|
||||
wchar_t wpath_abs[1024];
|
||||
DWORD written = GetFullPathNameW((wchar_t *)wpath, MA_Lengthof(wpath_abs), wpath_abs, 0);
|
||||
char16_t wpath_abs[1024];
|
||||
DWORD written = GetFullPathNameW((wchar_t *)wpath, MA_Lengthof(wpath_abs), (wchar_t *)wpath_abs, 0);
|
||||
if (written == 0)
|
||||
return S8_MakeEmpty();
|
||||
S8_String path = S8_FromWidecharEx(arena, wpath_abs, written);
|
||||
@@ -89,24 +89,24 @@ OS_API S8_String OS_GetAbsolutePath(MA_Arena *arena, S8_String relative) {
|
||||
}
|
||||
|
||||
OS_API bool OS_FileExists(S8_String path) {
|
||||
wchar_t wbuff[1024];
|
||||
char16_t wbuff[1024];
|
||||
UTF_CreateWidecharFromChar(wbuff, MA_Lengthof(wbuff), path.str, path.len);
|
||||
DWORD attribs = GetFileAttributesW(wbuff);
|
||||
DWORD attribs = GetFileAttributesW((wchar_t *)wbuff);
|
||||
bool result = attribs == INVALID_FILE_ATTRIBUTES ? false : true;
|
||||
return result;
|
||||
}
|
||||
|
||||
OS_API bool OS_IsDir(S8_String path) {
|
||||
wchar_t wbuff[1024];
|
||||
char16_t wbuff[1024];
|
||||
UTF_CreateWidecharFromChar(wbuff, MA_Lengthof(wbuff), path.str, path.len);
|
||||
DWORD dwAttrib = GetFileAttributesW(wbuff);
|
||||
DWORD dwAttrib = GetFileAttributesW((wchar_t *)wbuff);
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
OS_API bool OS_IsFile(S8_String path) {
|
||||
wchar_t wbuff[1024];
|
||||
char16_t wbuff[1024];
|
||||
UTF_CreateWidecharFromChar(wbuff, MA_Lengthof(wbuff), path.str, path.len);
|
||||
DWORD dwAttrib = GetFileAttributesW(wbuff);
|
||||
DWORD dwAttrib = GetFileAttributesW((wchar_t *)wbuff);
|
||||
bool is_file = (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES && is_file;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ OS_API void OS_Advance(OS_FileIter *it) {
|
||||
if (data->cFileName[0] == '.' && data->cFileName[1] == 0) continue;
|
||||
|
||||
it->is_directory = data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
it->filename = S8_FromWidecharEx(it->arena, data->cFileName, S8_WideLength(data->cFileName));
|
||||
it->filename = S8_FromWidecharEx(it->arena, (char16_t *)data->cFileName, S8_WideLength((char16_t *)data->cFileName));
|
||||
const char *is_dir = it->is_directory ? "/" : "";
|
||||
const char *separator = it->path.str[it->path.len - 1] == '/' ? "" : "/";
|
||||
it->relative_path = S8_Format(it->arena, "%.*s%s%.*s%s", S8_Expand(it->path), separator, S8_Expand(it->filename), is_dir);
|
||||
@@ -177,12 +177,12 @@ OS_API OS_FileIter OS_IterateFiles(MA_Arena *scratch_arena, S8_String path) {
|
||||
it.path = path;
|
||||
|
||||
S8_String modified_path = S8_Format(it.arena, "%.*s\\*", S8_Expand(path));
|
||||
wchar_t *wbuff = MA_PushArray(it.arena, wchar_t, modified_path.len + 1);
|
||||
char16_t *wbuff = MA_PushArray(it.arena, char16_t, modified_path.len + 1);
|
||||
int64_t wsize = UTF_CreateWidecharFromChar(wbuff, modified_path.len + 1, modified_path.str, modified_path.len);
|
||||
IO_Assert(wsize);
|
||||
|
||||
it.w32 = MA_PushStruct(it.arena, OS_Win32_FileIter);
|
||||
it.w32->handle = FindFirstFileW(wbuff, &it.w32->data);
|
||||
it.w32->handle = FindFirstFileW((wchar_t *)wbuff, &it.w32->data);
|
||||
if (it.w32->handle == INVALID_HANDLE_VALUE) {
|
||||
it.is_valid = false;
|
||||
return it;
|
||||
@@ -194,9 +194,9 @@ OS_API OS_FileIter OS_IterateFiles(MA_Arena *scratch_arena, S8_String path) {
|
||||
}
|
||||
|
||||
OS_API OS_Result OS_MakeDir(S8_String path) {
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), path.str, path.len);
|
||||
BOOL success = CreateDirectoryW(wpath, NULL);
|
||||
BOOL success = CreateDirectoryW((wchar_t *)wpath, NULL);
|
||||
OS_Result result = OS_SUCCESS;
|
||||
if (success == 0) {
|
||||
DWORD error = GetLastError();
|
||||
@@ -212,14 +212,14 @@ OS_API OS_Result OS_MakeDir(S8_String path) {
|
||||
}
|
||||
|
||||
OS_API OS_Result OS_CopyFile(S8_String from, S8_String to, bool overwrite) {
|
||||
wchar_t wfrom[1024];
|
||||
char16_t wfrom[1024];
|
||||
UTF_CreateWidecharFromChar(wfrom, MA_Lengthof(wfrom), from.str, from.len);
|
||||
|
||||
wchar_t wto[1024];
|
||||
char16_t wto[1024];
|
||||
UTF_CreateWidecharFromChar(wto, MA_Lengthof(wto), to.str, to.len);
|
||||
|
||||
BOOL fail_if_exists = !overwrite;
|
||||
BOOL success = CopyFileW(wfrom, wto, fail_if_exists);
|
||||
BOOL success = CopyFileW((wchar_t *)wfrom, (wchar_t *)wto, fail_if_exists);
|
||||
|
||||
OS_Result result = OS_SUCCESS;
|
||||
if (success == FALSE)
|
||||
@@ -228,9 +228,9 @@ OS_API OS_Result OS_CopyFile(S8_String from, S8_String to, bool overwrite) {
|
||||
}
|
||||
|
||||
OS_API OS_Result OS_DeleteFile(S8_String path) {
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), path.str, path.len);
|
||||
BOOL success = DeleteFileW(wpath);
|
||||
BOOL success = DeleteFileW((wchar_t *)wpath);
|
||||
OS_Result result = OS_SUCCESS;
|
||||
if (success == 0)
|
||||
result = OS_PATH_NOT_FOUND;
|
||||
@@ -274,7 +274,7 @@ OS_API OS_Result OS_DeleteDir(S8_String path, unsigned flags) {
|
||||
}
|
||||
|
||||
static OS_Result OS__WriteFile(S8_String path, S8_String data, bool append) {
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), path.str, path.len);
|
||||
OS_Result result = OS_FAILURE;
|
||||
|
||||
@@ -285,7 +285,7 @@ static OS_Result OS__WriteFile(S8_String path, S8_String data, bool append) {
|
||||
creation_disposition = OPEN_ALWAYS;
|
||||
}
|
||||
|
||||
HANDLE handle = CreateFileW(wpath, access, 0, NULL, creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
HANDLE handle = CreateFileW((wchar_t *)wpath, access, 0, NULL, creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
DWORD bytes_written = 0;
|
||||
IO_Assert(data.len == (DWORD)data.len); // @Todo: can only read 32 byte size files?
|
||||
@@ -314,9 +314,9 @@ OS_API S8_String OS_ReadFile(MA_Arena *arena, S8_String path) {
|
||||
S8_String result = S8_MakeEmpty();
|
||||
MA_Temp checkpoint = MA_BeginTemp(arena);
|
||||
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, MA_Lengthof(wpath), path.str, path.len);
|
||||
HANDLE handle = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
HANDLE handle = CreateFileW((wchar_t *)wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
LARGE_INTEGER file_size;
|
||||
if (GetFileSizeEx(handle, &file_size)) {
|
||||
@@ -347,9 +347,9 @@ OS_API int64_t OS_GetFileModTime(S8_String file) {
|
||||
FILETIME time = {0};
|
||||
WIN32_FIND_DATAW data;
|
||||
|
||||
wchar_t wpath[1024];
|
||||
char16_t wpath[1024];
|
||||
UTF_CreateWidecharFromChar(wpath, 1024, file.str, file.len);
|
||||
HANDLE handle = FindFirstFileW(wpath, &data);
|
||||
HANDLE handle = FindFirstFileW((wchar_t *)wpath, &data);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
FindClose(handle);
|
||||
time = data.ftLastWriteTime;
|
||||
|
||||
@@ -7,7 +7,7 @@ struct Process {
|
||||
Process RunEx(S8_String in_cmd) {
|
||||
MA_Scratch scratch;
|
||||
wchar_t *application_name = NULL;
|
||||
wchar_t *cmd = S8_ToWidechar(scratch, in_cmd);
|
||||
wchar_t *cmd = (wchar_t *)S8_ToWidechar(scratch, in_cmd);
|
||||
BOOL inherit_handles = FALSE;
|
||||
DWORD creation_flags = 0;
|
||||
void *enviroment = NULL;
|
||||
|
||||
@@ -410,7 +410,7 @@ S8_API int64_t S8_Length(char *string) {
|
||||
return len;
|
||||
}
|
||||
|
||||
S8_API int64_t S8_WideLength(wchar_t *string) {
|
||||
S8_API int64_t S8_WideLength(char16_t *string) {
|
||||
int64_t len = 0;
|
||||
while (*string++ != 0)
|
||||
len++;
|
||||
@@ -533,20 +533,20 @@ S8_API S8_String S8_AddF(S8_Allocator allocator, S8_List *list, const char *str,
|
||||
#ifdef FIRST_UTF_HEADER
|
||||
|
||||
S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string) {
|
||||
S8_ASSERT(sizeof(wchar_t) == 2);
|
||||
wchar_t *buffer = (wchar_t *)S8_ALLOCATE(allocator, sizeof(wchar_t) * (string.len + 1));
|
||||
S8_ASSERT(sizeof(char16_t) == 2);
|
||||
char16_t *buffer = (char16_t *)S8_ALLOCATE(allocator, sizeof(char16_t) * (string.len + 1));
|
||||
int64_t size = UTF_CreateWidecharFromChar(buffer, string.len + 1, string.str, string.len);
|
||||
S16_String result = {buffer, size};
|
||||
return result;
|
||||
}
|
||||
|
||||
S8_API wchar_t *S8_ToWidechar(S8_Allocator allocator, S8_String string) {
|
||||
S8_API char16_t *S8_ToWidechar(S8_Allocator allocator, S8_String string) {
|
||||
S16_String result = S8_ToWidecharEx(allocator, string);
|
||||
return result.str;
|
||||
}
|
||||
|
||||
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, wchar_t *wstring, int64_t wsize) {
|
||||
S8_ASSERT(sizeof(wchar_t) == 2);
|
||||
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, char16_t *wstring, int64_t wsize) {
|
||||
S8_ASSERT(sizeof(char16_t) == 2);
|
||||
|
||||
int64_t buffer_size = (wsize + 1) * 2;
|
||||
char *buffer = (char *)S8_ALLOCATE(allocator, buffer_size);
|
||||
@@ -557,7 +557,7 @@ S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, wchar_t *wstring, int
|
||||
return result;
|
||||
}
|
||||
|
||||
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, wchar_t *wstring) {
|
||||
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, char16_t *wstring) {
|
||||
int64_t size = S8_WideLength(wstring);
|
||||
S8_String result = S8_FromWidecharEx(allocator, wstring, size);
|
||||
return result;
|
||||
|
||||
@@ -82,7 +82,7 @@ struct S8_List {
|
||||
};
|
||||
|
||||
typedef struct S16_String {
|
||||
wchar_t *str;
|
||||
char16_t *str;
|
||||
int64_t len;
|
||||
} S16_String;
|
||||
|
||||
@@ -159,7 +159,7 @@ S8_API S8_String S8_GetNameNoExt(S8_String s);
|
||||
S8_API bool S8_IsPointerInside(S8_String string, char *p);
|
||||
S8_API S8_String S8_SkipToP(S8_String string, char *p);
|
||||
S8_API S8_String S8_SkipPast(S8_String string, S8_String a);
|
||||
S8_API int64_t S8_WideLength(wchar_t *string);
|
||||
S8_API int64_t S8_WideLength(char16_t *string);
|
||||
S8_API S8_String S8_MakeFromChar(char *string);
|
||||
S8_API S8_String S8_MakeEmpty(void);
|
||||
S8_API S8_List S8_MakeEmptyList(void);
|
||||
@@ -185,9 +185,9 @@ S8_API S8_Node *S8_Add(S8_Allocator allocator, S8_List *list, S8_String string)
|
||||
S8_API S8_String S8_AddF(S8_Allocator allocator, S8_List *list, const char *str, ...) S8__PrintfFormat(3, 4);
|
||||
|
||||
S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string);
|
||||
S8_API wchar_t *S8_ToWidechar(S8_Allocator allocator, S8_String string);
|
||||
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, wchar_t *wstring, int64_t wsize);
|
||||
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, wchar_t *wstring);
|
||||
S8_API char16_t *S8_ToWidechar(S8_Allocator allocator, S8_String string);
|
||||
S8_API S8_String S8_FromWidecharEx(S8_Allocator allocator, char16_t *wstring, int64_t wsize);
|
||||
S8_API S8_String S8_FromWidechar(S8_Allocator allocator, char16_t *wstring);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
inline S8_String operator""_s(const char *str, size_t size) { return {(char *)str, (int64_t)size}; }
|
||||
|
||||
@@ -136,7 +136,7 @@ UTF_API UTF16_Result UTF_ConvertUTF32ToUTF16(uint32_t codepoint) {
|
||||
break; \
|
||||
}
|
||||
|
||||
UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, wchar_t *in, int64_t inlen) {
|
||||
UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, char16_t *in, int64_t inlen) {
|
||||
int64_t outlen = 0;
|
||||
for (int64_t i = 0; i < inlen && in[i];) {
|
||||
UTF32_Result decode = UTF_ConvertUTF16ToUTF32((uint16_t *)(in + i), (int)(inlen - i));
|
||||
@@ -159,7 +159,7 @@ UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, wc
|
||||
return outlen;
|
||||
}
|
||||
|
||||
UTF_API int64_t UTF_CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen) {
|
||||
UTF_API int64_t UTF_CreateWidecharFromChar(char16_t *buffer, int64_t buffer_size, char *in, int64_t inlen) {
|
||||
int64_t outlen = 0;
|
||||
for (int64_t i = 0; i < inlen;) {
|
||||
UTF32_Result decode = UTF_ConvertUTF8ToUTF32(in + i, (int)(inlen - i));
|
||||
|
||||
@@ -45,8 +45,8 @@ UTF_API UTF32_Result UTF_ConvertUTF16ToUTF32(uint16_t *c, int max_advance);
|
||||
UTF_API UTF8_Result UTF_ConvertUTF32ToUTF8(uint32_t codepoint);
|
||||
UTF_API UTF32_Result UTF_ConvertUTF8ToUTF32(char *c, int max_advance);
|
||||
UTF_API UTF16_Result UTF_ConvertUTF32ToUTF16(uint32_t codepoint);
|
||||
UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, wchar_t *in, int64_t inlen);
|
||||
UTF_API int64_t UTF_CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen);
|
||||
UTF_API int64_t UTF_CreateCharFromWidechar(char *buffer, int64_t buffer_size, char16_t *in, int64_t inlen);
|
||||
UTF_API int64_t UTF_CreateWidecharFromChar(char16_t *buffer, int64_t buffer_size, char *in, int64_t inlen);
|
||||
UTF_API void UTF8_Advance(UTF8_Iter *iter);
|
||||
UTF_API UTF8_Iter UTF8_IterateEx(char *str, int len);
|
||||
UTF_API UTF8_Iter UTF8_Iterate(char *str);
|
||||
|
||||
Reference in New Issue
Block a user