- Updated posix/win32 stdlib namespacing

- Process stdlib
- Fix to void expression blocks
This commit is contained in:
Christoffer Lerno
2023-06-18 22:12:01 +02:00
committed by Christoffer Lerno
parent 5c9eb264e8
commit ab93389031
22 changed files with 835 additions and 187 deletions

View File

@@ -21,7 +21,7 @@ macro void! native_chdir(Path path)
@pool()
{
// TODO improve with better error handling.
if (win32::win32_SetCurrentDirectoryW(path.as_str().to_temp_utf16()!!)) return;
if (win32::setCurrentDirectoryW(path.as_str().to_temp_utf16()!!)) return;
};
return IoError.GENERAL_ERROR?;
$default:

View File

@@ -29,8 +29,8 @@ fn void*! native_fopen(String filename, String mode) @inline
$else
@pool()
{
$if env::os_is_win32():
void* file = (CFile)_wfopen(filename.to_temp_utf16(), filename.to_temp_utf16())!;
$if env::WIN32:
void* file = libc::_wfopen(filename.to_temp_utf16(), filename.to_temp_utf16())!;
$else
void* file = libc::fopen(filename.zstr_tcopy(), mode.zstr_tcopy());
$endif
@@ -52,7 +52,7 @@ fn void*! native_freopen(void* file, String filename, String mode) @inline
@pool()
{
$if env::os_is_win32():
file = _wfreopen(filename.to_temp_utf16(), mode.to_temp_utf16(), file)!;
file = libc::_wfreopen(filename.to_temp_utf16(), mode.to_temp_utf16(), file)!;
$else
file = libc::freopen(filename.zstr_tcopy(), mode.zstr_tcopy(), file);
$endif
@@ -67,12 +67,7 @@ fn void! native_fseek(void* file, isz offset, Seek seek_mode) @inline
if (native_fseek_fn) return native_fseek_fn(file, offset, seek_mode);
unreachable("Tried to call fseek without support.");
$else
$if env::os_is_win32():
bool success = _fseeki64(file, (long)offset, (int)seek_mode) == 0;
$else
bool success = libc::fseek(file, (SeekIndex)offset, (CInt)seek_mode) == 0;
$endif
if (!success) return file_seek_errno()?;
if (libc::fseek(file, (SeekIndex)offset, (CInt)seek_mode)) return file_seek_errno()?;
$endif
}
@@ -82,13 +77,8 @@ fn usz! native_ftell(CFile file) @inline
if (native_ftell_fn) return native_ftell_fn(file);
unreachable("Tried to call ftell without support.");
$else
$if env::os_is_win32():
long index = _ftelli64(file);
return index >= 0 ? index : file_seek_errno()?;
$else
SeekIndex index = libc::ftell(file);
return index >= 0 ? index : file_seek_errno()?;
$endif
long index = libc::ftell(file);
return index >= 0 ? (usz)index : file_seek_errno()?;
$endif
}
@@ -159,11 +149,5 @@ macro anyfault file_seek_errno() @local
}
}
// Win functions
extern fn void* _wfopen(Char16*, Char16*) @local @if(WIN32_LIBC);
extern fn void* _wfreopen(Char16*, Char16*, CFile) @local @if(WIN32_LIBC);
extern fn int _fseeki64(CFile, long, int) @local @if(WIN32_LIBC);
extern fn long _ftelli64(CFile) @local @if(WIN32_LIBC);
// Posix functions
extern fn CInt access(ZString path, CInt mode) @if(POSIX_LIBC);

View File

@@ -30,7 +30,7 @@ fn usz! native_file_size(String path)
{
Char16[] path16 = path.to_temp_utf16()!;
Win32_FILE_ATTRIBUTE_DATA data;
win32::win32_GetFileAttributesExW(path16, Win32_GET_FILEEX_INFO_LEVELS.STANDARD, &data);
win32::getFileAttributesExW(path16, Win32_GET_FILEEX_INFO_LEVELS.STANDARD, &data);
Win32_LARGE_INTEGER size;
size.lowPart = data.nFileSizeLow;
size.highPart = data.nFileSizeHigh;
@@ -42,7 +42,7 @@ fn bool native_file_or_dir_exists(String path)
{
@pool()
{
return (bool)win32::win32_PathFileExistsW(path.to_temp_utf16()) ?? false;
return (bool)win32::pathFileExistsW(path.to_temp_utf16()) ?? false;
};
}
@@ -64,11 +64,11 @@ fn void! native_rmtree(Path path)
Win32_WIN32_FIND_DATAW find_data;
String s = path.as_str().tconcat("\\*");
Win32_HANDLE find = win32::win32_FindFirstFileW(s.to_utf16(mem::temp()), &find_data)!;
Win32_HANDLE find = win32::findFirstFileW(s.to_utf16(mem::temp()), &find_data)!;
if (find == win32::INVALID_HANDLE_VALUE) return IoError.CANNOT_READ_DIR?;
defer win32::win32_FindClose(find);
defer win32::findClose(find);
do
{
String filename = string::from_zutf16(&find_data.cFileName, mem::temp())!;
@@ -80,9 +80,9 @@ fn void! native_rmtree(Path path)
}
else
{
win32::win32_DeleteFileW(file_path.as_str().to_utf16(mem::temp()));
win32::deleteFileW(file_path.as_str().to_utf16(mem::temp()));
}
} while (win32::win32_FindNextFileW(find, &find_data) != 0);
} while (win32::findNextFileW(find, &find_data) != 0);
os::native_rmdir(path)!;
}
@@ -90,10 +90,10 @@ fn Path! native_temp_directory(Allocator* using = mem::heap())
{
@stack_mem(256; Allocator* mem)
{
Win32_DWORD len = win32::win32_GetTempPathW(0, null);
Win32_DWORD len = win32::getTempPathW(0, null);
if (!len) return IoError.GENERAL_ERROR?;
Char16[] buff = malloc(Char16, len + 1, .using = mem);
if (!win32::win32_GetTempPathW(len, buff)) return IoError.GENERAL_ERROR?;
if (!win32::getTempPathW(len, buff)) return IoError.GENERAL_ERROR?;
return path::new(string::from_utf16(buff[:len], .using = mem), using);
};
}

View File

@@ -29,8 +29,8 @@ macro bool! native_mkdir(Path path, MkdirPermissions permissions)
@pool()
{
// TODO security attributes
if (win32::win32_CreateDirectoryW(path.as_str().to_temp_utf16()!!, null)) return true;
switch (win32::win32_GetLastError())
if (win32::createDirectoryW(path.as_str().to_temp_utf16()!!, null)) return true;
switch (win32::getLastError())
{
case win32::ERROR_ACCESS_DENIED:
return IoError.NO_PERMISSION?;

View File

@@ -26,8 +26,8 @@ macro bool! native_rmdir(Path path)
$case WIN32_LIBC:
@pool()
{
if (win32::win32_RemoveDirectoryW(path.as_str().to_temp_utf16()!!)) return true;
switch (win32::win32_GetLastError())
if (win32::removeDirectoryW(path.as_str().to_temp_utf16()!!)) return true;
switch (win32::getLastError())
{
case win32::ERROR_ACCESS_DENIED:
return IoError.NO_PERMISSION?;