This commit is contained in:
1 parent
9055c5c825
commit
5e67c596b9
43 files changed
+476
-450
No files matched your search
@@ -6,11 +6,11 @@
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
|
||||
wp_intern void initialise_arena_allocator(WpAllocator *allocator);
|
||||
wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj);
|
||||
wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj);
|
||||
wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
wp_intern void initialiseArenaAllocator(WpAllocator *allocator);
|
||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj);
|
||||
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj);
|
||||
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
|
||||
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj);
|
||||
|
||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||
@@ -20,7 +20,7 @@ WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||
return allocator;
|
||||
}
|
||||
|
||||
initialise_arena_allocator(&allocator);
|
||||
initialiseArenaAllocator(&allocator);
|
||||
|
||||
return allocator;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags fla
|
||||
return allocator;
|
||||
}
|
||||
|
||||
initialise_arena_allocator(&allocator);
|
||||
initialiseArenaAllocator(&allocator);
|
||||
|
||||
return allocator;
|
||||
}
|
||||
@@ -58,29 +58,29 @@ void wpMemArenaAllocatorDestroy(WpAllocator *allocator) {
|
||||
*allocator = (WpAllocator){0};
|
||||
}
|
||||
|
||||
wp_intern void initialise_arena_allocator(WpAllocator *allocator) {
|
||||
allocator->alloc = mem_arena_alloc;
|
||||
allocator->alloc_aligned = mem_arena_alloc_aligned;
|
||||
allocator->realloc = mem_arena_realloc;
|
||||
allocator->realloc_aligned = mem_arena_realloc_aligned;
|
||||
wp_intern void initialiseArenaAllocator(WpAllocator *allocator) {
|
||||
allocator->alloc = memArenaAlloc;
|
||||
allocator->alloc_aligned = memArenaAllocAligned;
|
||||
allocator->realloc = memArenaRealloc;
|
||||
allocator->realloc_aligned = memArenaReallocAligned;
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj) {
|
||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAlloc(arena, size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj) {
|
||||
wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaAllocAligned(arena, size, alignment);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
|
||||
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaRealloc(arena, ptr, old_size, new_size);
|
||||
}
|
||||
|
||||
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
|
||||
void *alloc_obj) {
|
||||
WpArena *arena = (WpArena *)alloc_obj;
|
||||
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
|
||||
|
||||
@@ -61,7 +61,7 @@ CPATH_JOIN_LOOP_END:
|
||||
return WP_CPATH_JOIN_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
WpStr8 *_dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels) {
|
||||
WpStr8 *dirUp(const WpAllocator *allocator, WpStr8RO *path, u64 levels) {
|
||||
WpStr8 *output = NULL;
|
||||
if (!allocator || !path) {
|
||||
goto RETURN_DIRUP;
|
||||
|
||||
@@ -25,8 +25,8 @@ BEGIN_C_LINKAGE
|
||||
#error "Unrecognised platform"
|
||||
#endif
|
||||
|
||||
#define wpCpathDirname(ALLOCATOR, PATH) _dirup(ALLOCATOR, PATH, 1)
|
||||
#define wpCpathDirup(ALLOCATOR, PATH, COUNT) _dirup(ALLOCATOR, PATH, COUNT)
|
||||
#define wpCpathDirname(ALLOCATOR, PATH) dirUp(ALLOCATOR, PATH, 1)
|
||||
#define wpCpathDirUp(ALLOCATOR, PATH, COUNT) dirUp(ALLOCATOR, PATH, COUNT)
|
||||
|
||||
typedef enum {
|
||||
WP_CPATH_JOIN_RESULT_SUCCESS = 0,
|
||||
@@ -36,7 +36,7 @@ typedef enum {
|
||||
} WpCpathJoinResult;
|
||||
|
||||
WpCpathJoinResult wpCpathJoinPath(WpStr8 *dst, const WpStr8List *parts);
|
||||
WpStr8 *_dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels);
|
||||
WpStr8 *dirUp(const WpAllocator *allocator, WpStr8RO *path, u64 levels);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
+13
-13
@@ -10,17 +10,17 @@
|
||||
WpFile *wpFileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
|
||||
wpDebugAssert(filepath->size < WP_PATH_MAX, "`filepath` exceeds max path limit.");
|
||||
return _fileOpen(allocator, filepath, mode);
|
||||
return fileOpen(allocator, filepath, mode);
|
||||
}
|
||||
|
||||
i64 wpFileGetCurrentPosition(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileSeek(file, 0, WP_SEEK_CURRENT);
|
||||
return fileSeek(file, 0, WP_SEEK_CURRENT);
|
||||
}
|
||||
|
||||
i64 wpFileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileSeek(file, offset, origin);
|
||||
return fileSeek(file, offset, origin);
|
||||
}
|
||||
|
||||
i64 wpFileGetLength(WpFile *file) {
|
||||
@@ -28,12 +28,12 @@ i64 wpFileGetLength(WpFile *file) {
|
||||
|
||||
i64 current = wpFileGetCurrentPosition(file);
|
||||
|
||||
_fileSeek(file, 0, WP_SEEK_END);
|
||||
fileSeek(file, 0, WP_SEEK_END);
|
||||
|
||||
i64 output = wpFileGetCurrentPosition(file);
|
||||
|
||||
// Restore position
|
||||
_fileSeek(file, current, WP_SEEK_START);
|
||||
fileSeek(file, current, WP_SEEK_START);
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -47,13 +47,13 @@ u64 wpFileRead(void *dst_buf, WpFile *file, u64 byte_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _fileRead(dst_buf, byte_count, file, file_length);
|
||||
return fileRead(dst_buf, byte_count, file, file_length);
|
||||
}
|
||||
|
||||
i64 wpFileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
wpDebugAssert(src_buf != NULL && file != NULL,
|
||||
"`src_buf` and `file` should not be NULL.");
|
||||
return _fileWrite(src_buf, file, byte_count);
|
||||
return fileWrite(src_buf, file, byte_count);
|
||||
}
|
||||
|
||||
u64 wpFileReadStr8(WpStr8 *str, WpFile *file) {
|
||||
@@ -87,7 +87,7 @@ u64 wpFileReadArray(WpArray dst_buf, WpFile *file, u64 item_count) {
|
||||
copy_byte_count = file_length <= dst_byte_capacity ? file_length : dst_byte_capacity;
|
||||
}
|
||||
|
||||
u64 byte_count = _fileRead(dst_buf, copy_byte_count, file, file_length);
|
||||
u64 byte_count = fileRead(dst_buf, copy_byte_count, file, file_length);
|
||||
if (byte_count == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ i64 wpFileWriteArray(const WpArray src_buf, WpFile *file, u64 item_count) {
|
||||
u64 req_byte_count = item_count * item_size;
|
||||
u64 to_copy = req_byte_count <= src_byte_count ? req_byte_count : src_byte_count;
|
||||
|
||||
i64 bytes_written = _fileWrite(src_buf, file, to_copy);
|
||||
i64 bytes_written = fileWrite(src_buf, file, to_copy);
|
||||
if (bytes_written < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -116,12 +116,12 @@ i64 wpFileWriteArray(const WpArray src_buf, WpFile *file, u64 item_count) {
|
||||
|
||||
i32 wpFileFlush(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileFlush(file);
|
||||
return fileFlush(file);
|
||||
}
|
||||
|
||||
i32 wpFileClose(WpFile *file) {
|
||||
wpDebugAssert(file != NULL, "`file` should not be NULL.");
|
||||
return _fileClose(file);
|
||||
return fileClose(file);
|
||||
}
|
||||
|
||||
i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
@@ -129,11 +129,11 @@ i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
"`old_filepath` and `new_filepath` should not be NULL");
|
||||
wpDebugAssert(old_filepath->size < WP_PATH_MAX, "`old_filepath` exceeds max path limit.");
|
||||
wpDebugAssert(new_filepath->size < WP_PATH_MAX, "`new_filepath` exceeds max path limit.");
|
||||
return _fileRename(old_filepath, new_filepath);
|
||||
return fileRename(old_filepath, new_filepath);
|
||||
}
|
||||
|
||||
i32 wpFileRemove(WpStr8RO *filepath) {
|
||||
wpDebugAssert(filepath != NULL, "`filepath` should not be NULL");
|
||||
wpDebugAssert(filepath->size < WP_PATH_MAX, "`filepath` exceeds max path limit.");
|
||||
return _fileRemove(filepath);
|
||||
return fileRemove(filepath);
|
||||
}
|
||||
+8
-8
@@ -61,14 +61,14 @@ i32 wpFileClose(WpFile *file);
|
||||
i32 wpFileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
i32 wpFileRemove(WpStr8RO *filepath);
|
||||
|
||||
wp_extern WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode);
|
||||
wp_extern i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin);
|
||||
wp_extern u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length);
|
||||
wp_extern i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count);
|
||||
wp_extern i32 _fileFlush(WpFile *file);
|
||||
wp_extern i32 _fileClose(WpFile *file);
|
||||
wp_extern i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
wp_extern i32 _fileRemove(WpStr8RO *filepath);
|
||||
wp_extern WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode);
|
||||
wp_extern i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin);
|
||||
wp_extern u64 fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length);
|
||||
wp_extern i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count);
|
||||
wp_extern i32 fileFlush(WpFile *file);
|
||||
wp_extern i32 fileClose(WpFile *file);
|
||||
wp_extern i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
|
||||
wp_extern i32 fileRemove(WpStr8RO *filepath);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -64,7 +64,7 @@ WpFile *wpFileStderr(void) {
|
||||
return &_stderr;
|
||||
}
|
||||
|
||||
WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
@@ -82,11 +82,11 @@ WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccess
|
||||
return output;
|
||||
}
|
||||
|
||||
i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
return lseek64(file->fd, offset, file_seek_origins[origin]);
|
||||
}
|
||||
|
||||
u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
u64 fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
u64 copy_byte_count = file_length <= byte_count ? file_length : byte_count;
|
||||
|
||||
i64 count = read(file->fd, dst_buf, copy_byte_count);
|
||||
@@ -95,19 +95,19 @@ u64 _fileRead(void *dst_buf, u64 byte_count, WpFile *file, u64 file_length) {
|
||||
return count;
|
||||
}
|
||||
|
||||
i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
return write(file->fd, src_buf, byte_count);
|
||||
}
|
||||
|
||||
i32 _fileFlush(WpFile *file) {
|
||||
i32 fileFlush(WpFile *file) {
|
||||
return fsync(file->fd);
|
||||
}
|
||||
|
||||
i32 _fileClose(WpFile *file) {
|
||||
i32 fileClose(WpFile *file) {
|
||||
return close(file->fd);
|
||||
}
|
||||
|
||||
i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
wp_persist c8 old_tmp[WP_PATH_MAX] = {0};
|
||||
wp_persist c8 new_tmp[WP_PATH_MAX] = {0};
|
||||
memset(old_tmp, 0, WP_PATH_MAX);
|
||||
@@ -117,13 +117,13 @@ i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
|
||||
i32 link_result = link((const char *)old_tmp, (const char *)new_tmp);
|
||||
if (link_result == 0) {
|
||||
_fileRemove(old_filepath);
|
||||
fileRemove(old_filepath);
|
||||
}
|
||||
|
||||
return link_result;
|
||||
}
|
||||
|
||||
i32 _fileRemove(WpStr8RO *filepath) {
|
||||
i32 fileRemove(WpStr8RO *filepath) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
|
||||
@@ -72,7 +72,7 @@ WpFile *wpFileStderr(void) {
|
||||
return &_stderr;
|
||||
}
|
||||
|
||||
WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
WpFile *fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccessMode mode) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
@@ -96,7 +96,7 @@ WpFile *_fileOpen(const WpAllocator *allocator, WpStr8RO *filepath, WpFileAccess
|
||||
return output;
|
||||
}
|
||||
|
||||
i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
i64 fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
LARGE_INTEGER distance = {0};
|
||||
LARGE_INTEGER output = {0};
|
||||
|
||||
@@ -109,7 +109,7 @@ i64 _fileSeek(WpFile *file, i64 offset, WpFileSeekOrigin origin) {
|
||||
return output.QuadPart;
|
||||
}
|
||||
|
||||
u64 _fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
u64 fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
u64 copy_byte_count = file_length <= byte_count ? file_length : byte_count;
|
||||
wpDebugAssert(copy_byte_count <= DWORD_MAX, "Attempting to read large number of bytes at once");
|
||||
|
||||
@@ -121,7 +121,7 @@ u64 _fileRead(void* dst_buf, u64 byte_count, WpFile* file, u64 file_length) {
|
||||
return (u64)read_count;
|
||||
}
|
||||
|
||||
i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
i64 fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
wpDebugAssert(byte_count <= DWORD_MAX, "Attempting to write large number of bytes at once");
|
||||
|
||||
DWORD write_count = 0;
|
||||
@@ -131,7 +131,7 @@ i64 _fileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||
return (i64)write_count;
|
||||
}
|
||||
|
||||
i32 _fileFlush(WpFile *file) {
|
||||
i32 fileFlush(WpFile *file) {
|
||||
if (!FlushFileBuffers(file->fh)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ i32 _fileFlush(WpFile *file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileClose(WpFile *file) {
|
||||
i32 fileClose(WpFile *file) {
|
||||
if (!CloseHandle(file->fh)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ i32 _fileClose(WpFile *file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
i32 fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
wp_persist c8 old_tmp[WP_PATH_MAX] = {0};
|
||||
wp_persist c8 new_tmp[WP_PATH_MAX] = {0};
|
||||
memset(old_tmp, 0, WP_PATH_MAX);
|
||||
@@ -162,7 +162,7 @@ i32 _fileRename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i32 _fileRemove(WpStr8RO *filepath) {
|
||||
i32 fileRemove(WpStr8RO *filepath) {
|
||||
wp_persist c8 tmp[WP_PATH_MAX] = {0};
|
||||
memset(tmp, 0, WP_PATH_MAX);
|
||||
memcpy(tmp, filepath->buf, filepath->size);
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
#endif
|
||||
|
||||
void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *output = _osMemAllocate(addr, size, access, flags, type);
|
||||
void *output = osMemAllocate(addr, size, access, flags, type);
|
||||
|
||||
if (type == WP_MEM_INIT_INITIALISED) {
|
||||
memset(output, 0, size);
|
||||
@@ -26,5 +26,5 @@ void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags fla
|
||||
}
|
||||
|
||||
void wpOsMemFree(void *ptr, u64 size) {
|
||||
_osMemFree(ptr, size);
|
||||
osMemFree(ptr, size);
|
||||
}
|
||||
+2
-2
@@ -23,8 +23,8 @@ BEGIN_C_LINKAGE
|
||||
void *wpOsMemAlloc(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
void wpOsMemFree(void *ptr, u64 size);
|
||||
|
||||
wp_extern void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
wp_extern void _osMemFree(void *ptr, u64 size);
|
||||
wp_extern void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type);
|
||||
wp_extern void osMemFree(void *ptr, u64 size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -18,7 +18,7 @@ wp_intern const i32 access_types[] = {
|
||||
[WP_MEM_ACCESS_READ_WRITE_EXEC] = PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
};
|
||||
|
||||
void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
(void)type;
|
||||
i32 alloc_flags = flags | MAP_ANON | MAP_PRIVATE;
|
||||
|
||||
@@ -29,7 +29,7 @@ void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags f
|
||||
return mmap(addr, size, access_types[access], alloc_flags, -1, 0);
|
||||
}
|
||||
|
||||
void _osMemFree(void *ptr, u64 size) {
|
||||
void osMemFree(void *ptr, u64 size) {
|
||||
munmap(ptr, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ wp_intern const i32 access_types[] = {
|
||||
[WP_MEM_ACCESS_READ_WRITE_EXEC] = PAGE_EXECUTE_READWRITE,
|
||||
};
|
||||
|
||||
void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
void *osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags flags, WpMemInitType type) {
|
||||
// Ensure memory is committed if it's meant to be initialised
|
||||
if (type == WP_MEM_INIT_INITIALISED) {
|
||||
flags |= WP_MEM_ALLOC_COMMIT;
|
||||
@@ -30,7 +30,7 @@ void *_osMemAllocate(void *addr, u64 size, WpMemAccess access, WpMemAllocFlags f
|
||||
return VirtualAlloc(addr, (SIZE_T)size, flags, access_types[access]);
|
||||
}
|
||||
|
||||
void _osMemFree(void *ptr, u64 size) {
|
||||
void osMemFree(void *ptr, u64 size) {
|
||||
VirtualFree(ptr, size, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ wp_intern WpCmdResult executeCommand(WpStr8RO *cmd, WpCmdOutHandling out_handlin
|
||||
}
|
||||
|
||||
i32 st = EXIT_SUCCESS;
|
||||
err = _getOutputStatus(fp, &st);
|
||||
err = getOutputStatus(fp, &st);
|
||||
if (err > WP_SHELL_ERR_NO_ERROR) {
|
||||
output = wpCmdNoExit(err);
|
||||
goto executeCommand_CLOSE;
|
||||
|
||||
@@ -20,7 +20,7 @@ BEGIN_C_LINKAGE
|
||||
|
||||
WpCmdResult wpShellCommanderExecute(WpCmdOutHandling out_handling, WpStr8 *out_buf, const WpStr8List *cmd);
|
||||
|
||||
wp_extern WpCmdError _getOutputStatus(FILE *fp, i32 *status_out);
|
||||
wp_extern WpCmdError getOutputStatus(FILE *fp, i32 *status_out);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
WpCmdError _getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
WpCmdError getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
*status_out = wpShellUtilsPclose(fp);
|
||||
|
||||
if (!WIFEXITED(*status_out)) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "../../utils/shell_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
WpCmdError _getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
WpCmdError getOutputStatus(FILE *fp, i32 *status_out) {
|
||||
if (!feof(fp)) {
|
||||
// Ensure process is closed on failure
|
||||
wpShellUtilsPclose(fp);
|
||||
|
||||
@@ -29,7 +29,7 @@ wp_intern WpStr8RO colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_CLEAR] = wpStr8LitRoInitialiserList("\033[0m"),
|
||||
};
|
||||
|
||||
void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
void printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
printf(WP_STR8_SPEC WP_STR8_SPEC, wpStr8Varg(colours[colour]), wpStr8Varg((*text)));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ void wpShellTermcolourPrintText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
return;
|
||||
}
|
||||
|
||||
_printColouredText(text, colour);
|
||||
printColouredText(text, colour);
|
||||
}
|
||||
|
||||
void wpShellTermcolourClearColour(void) {
|
||||
WpStr8RO empty = wpStr8LitRo("");
|
||||
_printColouredText(&empty, WP_TERM_COLOUR_CLEAR);
|
||||
printColouredText(&empty, WP_TERM_COLOUR_CLEAR);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ BEGIN_C_LINKAGE
|
||||
void wpShellTermcolourPrintText(WpStr8RO *text, WpTerminalColour colour);
|
||||
void wpShellTermcolourClearColour(void);
|
||||
|
||||
wp_extern void _printColouredText(WpStr8RO *text, WpTerminalColour colour);
|
||||
wp_extern void printColouredText(WpStr8RO *text, WpTerminalColour colour);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -22,7 +22,7 @@ struct TermcolourData {
|
||||
wpMiscUtilsReservePadding(sizeof(HANDLE) + sizeof(WORD) + sizeof(WORD));
|
||||
};
|
||||
|
||||
wp_intern void init_data(TermcolourData *data);
|
||||
wp_intern void initData(TermcolourData *data);
|
||||
|
||||
wp_intern WORD colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_FG_BLACK] = 0,
|
||||
@@ -43,10 +43,10 @@ wp_intern WORD colours[COUNT_TERM_COLOUR] = {
|
||||
[WP_TERM_COLOUR_FG_BR_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||
};
|
||||
|
||||
void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
void printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
wp_persist TermcolourData data = {0};
|
||||
if (data.handle == 0) {
|
||||
init_data(&data);
|
||||
initData(&data);
|
||||
}
|
||||
|
||||
if (colour == WP_TERM_COLOUR_CLEAR) {
|
||||
@@ -59,7 +59,7 @@ void _printColouredText(WpStr8RO *text, WpTerminalColour colour) {
|
||||
printf(WP_STR8_SPEC, wpStr8Varg((*text)));
|
||||
}
|
||||
|
||||
wp_intern void init_data(TermcolourData *data) {
|
||||
wp_intern void initData(TermcolourData *data) {
|
||||
// create handle
|
||||
data->handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
|
||||
Reference in new issue
Block a user