Get latest changes from upstream
This commit is contained in:
+30
-30
@@ -209,7 +209,7 @@ DN_API void DN_OS_GenBytesSecure(void *buffer, DN_U32 size)
|
||||
|
||||
DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_OSDiskSpace result = {};
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
@@ -233,7 +233,7 @@ DN_API DN_OSDiskSpace DN_OS_DiskSpace(DN_Str8 path)
|
||||
|
||||
DN_API bool DN_OS_SetEnvVar(DN_Str8 name, DN_Str8 value)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 name16 = DN_OS_W32Str8ToStr16(&scratch.arena, name);
|
||||
DN_Str16 value16 = DN_OS_W32Str8ToStr16(&scratch.arena, value);
|
||||
bool result = SetEnvironmentVariableW(name16.data, value16.data) != 0;
|
||||
@@ -246,7 +246,7 @@ DN_API DN_Str8 DN_OS_EXEPath(DN_Arena *arena)
|
||||
DN_Str8 result = {};
|
||||
if (!arena)
|
||||
return result;
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_Str16 exe_dir16 = DN_OS_W32EXEPathW(&scratch.arena);
|
||||
result = DN_OS_W32Str16ToStr8(arena, exe_dir16);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
@@ -286,7 +286,7 @@ static DN_U64 DN_OS_W32FileTimeToSeconds_(FILETIME const *time)
|
||||
DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err)
|
||||
{
|
||||
bool result = false;
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 src16 = DN_OS_W32Str8ToStr16(&scratch.arena, src);
|
||||
DN_Str16 dest16 = DN_OS_W32Str8ToStr16(&scratch.arena, dest);
|
||||
|
||||
@@ -310,7 +310,7 @@ DN_API bool DN_OS_FileCopy(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink
|
||||
DN_API bool DN_OS_FileMove(DN_Str8 src, DN_Str8 dest, bool overwrite, DN_ErrSink *err)
|
||||
{
|
||||
bool result = false;
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 src16 = DN_OS_W32Str8ToStr16(&scratch.arena, src);
|
||||
DN_Str16 dest16 = DN_OS_W32Str8ToStr16(&scratch.arena, dest);
|
||||
|
||||
@@ -366,7 +366,7 @@ DN_API DN_OSFile DN_OS_FileOpen(DN_Str8 path, DN_OSFileOpen open_mode, DN_OSFile
|
||||
access_mode |= GENERIC_EXECUTE;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
void *handle = CreateFileW(/*LPCWSTR lpFileName*/ path16.data,
|
||||
/*DWORD dwDesiredAccess*/ access_mode,
|
||||
@@ -395,9 +395,9 @@ DN_API DN_OSFileRead DN_OS_FileRead(DN_OSFile *file, void *buffer, DN_USize size
|
||||
if (!file || !file->handle || file->error || !buffer || size <= 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
if (!DN_Check(size <= (unsigned long)-1)) {
|
||||
DN_Str8x32 buffer_size_str8 = DN_ByteCountStr8x32(size);
|
||||
DN_Str8x32 buffer_size_str8 = DN_Str8x32FromByteCountU64Auto(size);
|
||||
DN_ErrSinkAppendF(
|
||||
err,
|
||||
1 /*error_code*/,
|
||||
@@ -455,9 +455,9 @@ DN_API bool DN_OS_FileWritePtr(DN_OSFile *file, void const *buffer, DN_USize siz
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_Str8x32 buffer_size_str8 = DN_ByteCountStr8x32(size);
|
||||
DN_Str8x32 buffer_size_str8 = DN_Str8x32FromByteCountU64Auto(size);
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to write buffer (%.*s) to file handle: %.*s", DN_Str8PrintFmt(buffer_size_str8), DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
}
|
||||
@@ -471,7 +471,7 @@ DN_API bool DN_OS_FileFlush(DN_OSFile *file, DN_ErrSink *err)
|
||||
|
||||
BOOL result = FlushFileBuffers(DN_Cast(HANDLE) file->handle);
|
||||
if (!result) {
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32Error win_error = DN_OS_W32LastError(&scratch.arena);
|
||||
DN_ErrSinkAppendF(err, win_error.code, "Failed to flush file buffer to disk: %.*s", DN_Str8PrintFmt(win_error.msg));
|
||||
DN_TCScratchEnd(&scratch);
|
||||
@@ -494,7 +494,7 @@ DN_API DN_OSPathInfo DN_OS_PathInfo(DN_Str8 path)
|
||||
if (path.size == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
@@ -530,7 +530,7 @@ DN_API bool DN_OS_PathDelete(DN_Str8 path)
|
||||
if (path.size == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
result = DeleteFileW(path16.data);
|
||||
@@ -547,7 +547,7 @@ DN_API bool DN_OS_PathIsFile(DN_Str8 path)
|
||||
if (path.size == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
@@ -565,7 +565,7 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
if (path.size == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
if (path16.size) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrib_data = {};
|
||||
@@ -581,7 +581,7 @@ DN_API bool DN_OS_PathIsDir(DN_Str8 path)
|
||||
DN_API bool DN_OS_PathMakeDir(DN_Str8 path)
|
||||
{
|
||||
bool result = true;
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str16 path16 = DN_OS_W32Str8ToStr16(&scratch.arena, path);
|
||||
|
||||
// NOTE: Go back from the end of the string to all the directories in the
|
||||
@@ -636,7 +636,7 @@ DN_API bool DN_OS_PathIterateDir(DN_Str8 path, DN_OSDirIterator *it)
|
||||
if (path.size == 0 || !it || path.size <= 0)
|
||||
return false;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_OSW32FolderIteratorW wide_it = {};
|
||||
DN_Str16 path16 = {};
|
||||
if (it->handle) {
|
||||
@@ -716,7 +716,7 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DWORD stdout_bytes_available = 0;
|
||||
DWORD stderr_bytes_available = 0;
|
||||
PeekNamedPipe(handle.stdout_read, nullptr, 0, nullptr, &stdout_bytes_available, nullptr);
|
||||
@@ -822,7 +822,7 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle, DN_Arena *are
|
||||
return result;
|
||||
}
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_Str8Builder stdout_builder = {};
|
||||
DN_Str8Builder stderr_builder = {};
|
||||
if (arena) {
|
||||
@@ -845,8 +845,8 @@ DN_API DN_OSExecResult DN_OS_ExecWait(DN_OSExecAsyncHandle handle, DN_Arena *are
|
||||
}
|
||||
|
||||
// NOTE: Get stdout/stderr. If no arena is passed this is a no-op
|
||||
result.stdout_text = DN_Str8BuilderBuild(&stdout_builder, arena);
|
||||
result.stderr_text = DN_Str8BuilderBuild(&stderr_builder, arena);
|
||||
result.stdout_text = DN_Str8FromStr8BuilderArena(&stdout_builder, arena);
|
||||
result.stderr_text = DN_Str8FromStr8BuilderArena(&stderr_builder, arena);
|
||||
DN_TCScratchEnd(&scratch);
|
||||
return result;
|
||||
}
|
||||
@@ -858,7 +858,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
if (cmd_line.count == 0)
|
||||
return result;
|
||||
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
DN_Str8 cmd_rendered = DN_Str8SliceRender(cmd_line, DN_Str8Lit(" "), &scratch.arena);
|
||||
DN_Str16 cmd16 = DN_OS_W32Str8ToStr16(&scratch.arena, cmd_rendered);
|
||||
DN_Str16 working_dir16 = DN_OS_W32Str8ToStr16(&scratch.arena, args->working_dir);
|
||||
@@ -868,7 +868,7 @@ DN_API DN_OSExecAsyncHandle DN_OS_ExecAsync(DN_Str8Slice cmd_line, DN_OSExecArgs
|
||||
if (env_builder.string_size)
|
||||
DN_Str8BuilderAppendRef(&env_builder, DN_Str8Lit("\0"));
|
||||
|
||||
DN_Str8 env_block8 = DN_Str8BuilderBuildDelimited(&env_builder, DN_Str8Lit("\0"), &scratch.arena);
|
||||
DN_Str8 env_block8 = DN_Str8FromStr8BuilderDelimitArena(&env_builder, DN_Str8Lit("\0"), &scratch.arena);
|
||||
DN_Str16 env_block16 = {};
|
||||
if (env_block8.size)
|
||||
env_block16 = DN_OS_W32Str8ToStr16(&scratch.arena, env_block8);
|
||||
@@ -1305,7 +1305,7 @@ DN_API void DN_OS_W32ThreadSetName(DN_Str8 name)
|
||||
//
|
||||
// See: https://learn.microsoft.com/en-us/windows/w32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
|
||||
DN_OSW32Core *w32 = DN_OS_W32GetCore();
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(nullptr, 0);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(nullptr, 0);
|
||||
if (w32->set_thread_description) {
|
||||
DN_Str16 name16 = DN_OS_W32Str8ToStr16(&scratch.arena, name);
|
||||
w32->set_thread_description(GetCurrentThread(), (WCHAR *)name16.data);
|
||||
@@ -1420,7 +1420,7 @@ void DN_OS_HttpRequestWin32Callback(HINTERNET session, DWORD *dwContext, DWORD d
|
||||
if (request) {
|
||||
bool read_complete = dwInternetStatus == WINHTTP_CALLBACK_STATUS_READ_COMPLETE && dwStatusInformationLength == 0;
|
||||
if (read_complete)
|
||||
response->body = DN_Str8BuilderBuild(&response->builder, response->arena);
|
||||
response->body = DN_Str8FromStr8BuilderArena(&response->builder, response->arena);
|
||||
|
||||
if (read_complete || dwInternetStatus == WINHTTP_CALLBACK_STATUS_REQUEST_ERROR || error.code) {
|
||||
DN_OS_SemaphoreIncrement(&response->on_complete_semaphore, 1);
|
||||
@@ -1449,7 +1449,7 @@ DN_API void DN_OS_HttpRequestAsync(DN_OSHttpResponse *response,
|
||||
response->arena = arena;
|
||||
response->builder = DN_Str8BuilderFromArena(response->scratch_arena.mem ? &response->scratch_arena : &response->tmp_arena);
|
||||
|
||||
DN_TCScratch scratch_ = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch_ = DN_TCScratchBeginArena(&arena, 1);
|
||||
if (!response->scratch_arena.mem)
|
||||
response->scratch_arena = scratch_.arena;
|
||||
|
||||
@@ -1743,7 +1743,7 @@ DN_API DN_Str8 DN_OS_W32Str16ToStr8FromHeap(DN_Str16 src)
|
||||
// NOTE: Windows Executable Directory //////////////////////////////////////////
|
||||
DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_Str16 result = {};
|
||||
DN_USize module_size = 0;
|
||||
wchar_t *module_path = nullptr;
|
||||
@@ -1772,7 +1772,7 @@ DN_API DN_Str16 DN_OS_W32EXEPathW(DN_Arena *arena)
|
||||
DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
{
|
||||
// TODO(doyle): Implement a DN_Str16_BinarySearchReverse
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_Str16 result = {};
|
||||
DN_USize module_size = 0;
|
||||
wchar_t *module_path = nullptr;
|
||||
@@ -1800,7 +1800,7 @@ DN_API DN_Str16 DN_OS_W32EXEDirW(DN_Arena *arena)
|
||||
|
||||
DN_API DN_Str8 DN_OS_W32WorkingDir(DN_Arena *arena, DN_Str8 suffix)
|
||||
{
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
DN_Str16 suffix16 = DN_OS_W32Str8ToStr16(&scratch.arena, suffix);
|
||||
DN_Str16 dir16 = DN_OS_W32WorkingDirW(&scratch.arena, suffix16);
|
||||
DN_Str8 result = DN_OS_W32Str16ToStr8(arena, dir16);
|
||||
@@ -1814,7 +1814,7 @@ DN_API DN_Str16 DN_OS_W32WorkingDirW(DN_Arena *arena, DN_Str16 suffix)
|
||||
DN_Str16 result = {};
|
||||
|
||||
// NOTE: required_size is the size required *including* the null-terminator
|
||||
DN_TCScratch scratch = DN_TCScratchBegin(&arena, 1);
|
||||
DN_TCScratch scratch = DN_TCScratchBeginArena(&arena, 1);
|
||||
unsigned long required_size = GetCurrentDirectoryW(0, nullptr);
|
||||
unsigned long desired_size = required_size + DN_Cast(unsigned long) suffix.size;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user