From d5a727a062e4d727491f4e7f047269d60a93a8cf Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 17 Nov 2024 05:24:04 +0100 Subject: Remove lots of dependencies --- kit/shared_memory.win32.c | 91 ----------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 kit/shared_memory.win32.c (limited to 'kit/shared_memory.win32.c') 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 - -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 -- cgit v1.2.3