diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-11-17 05:24:04 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-11-17 05:24:04 +0100 |
commit | d5a727a062e4d727491f4e7f047269d60a93a8cf (patch) | |
tree | 565aec155ab056f1bef8ddc7dc78d52e65aa76b7 /kit/shared_memory.win32.c | |
parent | 4ba961dcbf60f7c12f53f46baa261757e15d5931 (diff) | |
download | saw-d5a727a062e4d727491f4e7f047269d60a93a8cf.zip |
Remove lots of dependencies
Diffstat (limited to 'kit/shared_memory.win32.c')
-rw-r--r-- | kit/shared_memory.win32.c | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/kit/shared_memory.win32.c b/kit/shared_memory.win32.c deleted file mode 100644 index f1d24d0..0000000 --- a/kit/shared_memory.win32.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "shared_memory.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# ifndef NOMINMAX -# define NOMINMAX -# endif -# include <windows.h> - -kit_shared_memory_t kit_shared_memory_open(kit_str_t name, i64 size, - i32 mode) { - kit_shared_memory_t mem; - memset(&mem, 0, sizeof mem); - - char buf[264] = "Global\\"; - - assert(size > 0); - assert(name.size > 0); - assert(name.size + 8 < (i64) sizeof buf); - assert(name.values != NULL); - - if (name.size <= 0) { - mem.status = KIT_ERROR_INVALID_NAME; - return mem; - } - - if (name.size + 8 >= (i64) sizeof buf) { - mem.status = KIT_ERROR_NAME_TOO_LONG; - return mem; - } - - for (i64 i = 0; i < name.size; i++) - if (name.values[i] == '/' || name.values[i] == '\\') { - mem.status = KIT_ERROR_INVALID_NAME; - return mem; - } - - memcpy(buf + 7, name.values, name.size); - buf[7 + name.size] = '\0'; - - HANDLE h = mode == KIT_SHARED_MEMORY_CREATE - ? CreateFileMappingA( - INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, - (DWORD) (size >> 32), (DWORD) size, buf) - : OpenFileMappingA(FILE_MAP_ALL_ACCESS, 0, buf); - - if (h == INVALID_HANDLE_VALUE) { - mem.status = KIT_ERROR_OPEN_FAILED; - return mem; - } - - void *p = MapViewOfFile(h, FILE_MAP_ALL_ACCESS, 0, 0, - (SIZE_T) size); - - if (p == NULL) { - CloseHandle(h); - mem.status = KIT_ERROR_MAP_FAILED; - return mem; - } - - mem.status = KIT_OK; - mem.size = size; - mem.bytes = (u8 *) p; - mem._handle = h; - return mem; -} - -s32 kit_shared_memory_close(kit_shared_memory_t *mem) { - assert(mem != NULL); - - i32 status = KIT_OK; - - if (!UnmapViewOfFile(mem->bytes)) - status |= KIT_ERROR_UNMAP_FAILED; - if (!CloseHandle(mem->_handle)) - status |= KIT_ERROR_UNLINK_FAILED; - - return status; -} - -s32 kit_shared_memory_clean(kit_str_t name) { - // Do nothing. - // - - (void) name; - - return KIT_OK; -} -#endif |