Commit: 47ed0e4eb83b38dac3216e2c67f5366228f9a4b6
Parent: bb06bbeb3f69a70b1d7d59da62a9dbefd31f0ece
Author: Randy Palamar
Date: Tue, 2 Jul 2024 14:26:46 -0600
add w32 pipe code
Diffstat:
| M | os_win32.c | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
| M | util.h | | | 46 | ++++++++++++++++++++++++---------------------- |
2 files changed, 64 insertions(+), 22 deletions(-)
diff --git a/os_win32.c b/os_win32.c
@@ -4,6 +4,17 @@
#include <memoryapi.h>
#include <sysinfoapi.h>
+/* NOTE: copied from wtypes.h; we don't actually use this type but winbase.h needs it defined */
+typedef void *HWND;
+#include <winbase.h>
+
+#define OS_INVALID_FILE (INVALID_HANDLE_VALUE)
+typedef HANDLE os_file;
+typedef struct {
+ os_file file;
+ char *name;
+} os_pipe;
+
typedef FILETIME os_filetime;
typedef struct {
@@ -74,3 +85,32 @@ os_get_file_stats(char *fname)
.timestamp = fileinfo.ftLastWriteTime,
};
}
+
+/* NOTE: win32 doesn't pollute the filesystem so no need to waste the user's time */
+static void
+os_close_named_pipe(os_pipe p)
+{
+}
+
+static os_pipe
+os_open_named_pipe(char *name)
+{
+ HANDLE h = CreateNamedPipeA(name, PIPE_ACCESS_INBOUND, PIPE_TYPE_BYTE, 1,
+ 0, 1 * MEGABYTE, 0, 0);
+ return (os_pipe){.file = h, .name = name};
+}
+
+static b32
+os_poll_pipe(os_pipe p)
+{
+ DWORD bytes_available = 0;
+ return PeekNamedPipe(p.file, 0, 1 * MEGABYTE, 0, &bytes_available, 0) && bytes_available;
+}
+
+static size
+os_read_pipe_data(os_pipe p, void *buf, size len)
+{
+ DWORD total_read = 0;
+ ReadFile(p.file, buf, len, &total_read, 0);
+ return total_read;
+}
diff --git a/util.h b/util.h
@@ -6,13 +6,24 @@
#include <stdint.h>
#ifdef _DEBUG
-#define ASSERT(c) do { if (!(c)) asm("int3; nop"); } while (0);
-#define DEBUG_EXPORT
+ #define ASSERT(c) do { if (!(c)) asm("int3; nop"); } while (0);
+ #define DEBUG_EXPORT
#else
-#define ASSERT(c)
-#define DEBUG_EXPORT static
+ #define ASSERT(c)
+ #define DEBUG_EXPORT static
#endif
+#define MEGABYTE (1024ULL * 1024ULL)
+#define GIGABYTE (1024ULL * 1024ULL * 1024ULL)
+
+#define U32_MAX (0xFFFFFFFFUL)
+
+#define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a))
+#define ABS(x) ((x) < 0 ? (-x) : (x))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
+#define ISPOWEROF2(a) (((a) & ((a) - 1)) == 0)
+
typedef uint8_t u8;
typedef int16_t i16;
typedef int32_t i32;
@@ -65,16 +76,18 @@ enum program_flags {
};
#include "util.c"
+
+
#if defined(__unix__)
-#define GL_GLEXT_PROTOTYPES 1
-#include <GL/glcorearb.h>
-#include <GL/glext.h>
-#include "os_unix.c"
+ #define GL_GLEXT_PROTOTYPES 1
+ #include <GL/glcorearb.h>
+ #include <GL/glext.h>
+ #include "os_unix.c"
#elif defined(_WIN32)
-#include <glad.h>
-#include "os_win32.c"
+ #include <glad.h>
+ #include "os_win32.c"
#else
-#error Unsupported Platform!
+ #error Unsupported Platform!
#endif
typedef struct {
@@ -120,15 +133,4 @@ typedef struct {
u32 partial_transfer_count;
} BeamformerCtx;
-#define MEGABYTE (1024ULL * 1024ULL)
-#define GIGABYTE (1024ULL * 1024ULL * 1024ULL)
-
-#define U32_MAX (0xFFFFFFFFUL)
-
-#define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a))
-#define ABS(x) ((x) < 0 ? (-x) : (x))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
-#define ISPOWEROF2(a) (((a) & ((a) - 1)) == 0)
-
#endif /*_UTIL_H_ */