From 6e6e07fff75051d77fadd5d5b045995ccb54ae8a Mon Sep 17 00:00:00 2001 From: tmeissner Date: Thu, 2 May 2019 15:15:04 +0200 Subject: [PATCH] Add detecttion of OS with preprocessor --- chapter_04/prompt.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/chapter_04/prompt.c b/chapter_04/prompt.c index 5df22c0..8ccba35 100644 --- a/chapter_04/prompt.c +++ b/chapter_04/prompt.c @@ -1,7 +1,33 @@ #include #include + +/* If we are on Windows compile these functions */ +#ifdef _WIN32 +#include +#include + +static char buffer[2048]; + +/* Fake readline function */ +char* readline(char* prompt) { + fputs(prompt, stdout); + fgets(buffer, 2048, stdin); + char* cpy = malloc(strlen(buffer)+1); + assert(cpy != NULL) + strcpy(cpy, buffer); + cpy[strlen(cpy)-1] = '\0'; + return cpy; +} + +/* Fake add_history function */ +void add_history(char* unused) {} + +/* Otherwise include the editline headers + could use __APPLE__ for detection of OSX */ +#else #include +#endif int main(int argc, char const *argv[])