Compare commits

..

4 Commits

Author SHA1 Message Date
William Bell
a9b1d23f79 fix windows build 2025-10-21 21:43:02 +01:00
William Bell
6d3e79b731 fix window build 2025-10-21 21:32:02 +01:00
William Bell
b3ee64d294 fix windows build 2025-10-21 21:08:27 +01:00
William Bell
e6ec0fa38a fix windows building 2025-10-21 20:57:22 +01:00
2 changed files with 41 additions and 0 deletions

View File

@@ -19,6 +19,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef _WIN32
#include <windows.h>
#endif
char *get_current_directory() {
char *buffer = NULL;

View File

@@ -23,6 +23,7 @@
#include <malloc.h>
#endif
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
FILE *fmemopen(void *buf, size_t size, const char *mode) {
if (strchr(mode, 'r') == NULL) {
return NULL;
@@ -41,6 +42,43 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
return tmp;
}
// Only define ssize_t if it doesn't already exist
#ifndef _SSIZE_T_DEFINED
typedef long ssize_t;
#define _SSIZE_T_DEFINED
#endif
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
if (!lineptr || !n || !stream) return -1;
size_t pos = 0;
int c;
if (*lineptr == NULL || *n == 0) {
*n = 128;
*lineptr = malloc(*n);
if (!*lineptr) return -1;
}
while ((c = fgetc(stream)) != EOF) {
if (pos + 1 >= *n) {
*n *= 2;
char *tmp = realloc(*lineptr, *n);
if (!tmp) return -1;
*lineptr = tmp;
}
(*lineptr)[pos++] = c;
if (c == '\n')
break;
}
if (pos == 0 && c == EOF)
return -1;
(*lineptr)[pos] = '\0';
return (ssize_t)pos;
}
#else
#include "../external/linenoise/linenoise.h"
#endif