diff --git a/bsnes/gb/Core/debugger.c b/bsnes/gb/Core/debugger.c index df480f34..db2cbe50 100644 --- a/bsnes/gb/Core/debugger.c +++ b/bsnes/gb/Core/debugger.c @@ -2,6 +2,9 @@ #include #include #include "gb.h" +#ifdef _WIN32 + #include "../Windows/getline.h" +#endif typedef struct { bool has_bank; diff --git a/bsnes/gb/Core/gb.c b/bsnes/gb/Core/gb.c index 08d2183c..43a792c4 100644 --- a/bsnes/gb/Core/gb.c +++ b/bsnes/gb/Core/gb.c @@ -12,7 +12,9 @@ #endif #include "random.h" #include "gb.h" - +#ifdef _WIN32 + #include "../Windows/getline.h" +#endif #ifdef DISABLE_REWIND #define GB_rewind_free(...) diff --git a/bsnes/gb/Windows/getline.h b/bsnes/gb/Windows/getline.h new file mode 100644 index 00000000..ea90abcb --- /dev/null +++ b/bsnes/gb/Windows/getline.h @@ -0,0 +1,52 @@ +/* This code is public domain -- Will Hartung 4/9/09 */ +static inline size_t getline(char **lineptr, size_t *n, FILE *stream) { + char *bufptr = NULL; + char *p = bufptr; + size_t size; + int c; + + if (lineptr == NULL) { + return -1; + } + if (stream == NULL) { + return -1; + } + if (n == NULL) { + return -1; + } + bufptr = *lineptr; + size = *n; + + c = fgetc(stream); + if (c == EOF) { + return -1; + } + if (bufptr == NULL) { + bufptr = malloc(128); + if (bufptr == NULL) { + return -1; + } + size = 128; + } + p = bufptr; + while (c != EOF) { + if ((p - bufptr) > (size - 1)) { + size = size + 128; + bufptr = realloc(bufptr, size); + if (bufptr == NULL) { + return -1; + } + } + *p++ = c; + if (c == '\n') { + break; + } + c = fgetc(stream); + } + + *p++ = '\0'; + *lineptr = bufptr; + *n = size; + + return p - bufptr - 1; +}