Browse Source

Add detecttion of OS with preprocessor

master
T. Meissner 5 years ago
parent
commit
6e6e07fff7
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      chapter_04/prompt.c

+ 26
- 0
chapter_04/prompt.c View File

@ -1,7 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
/* If we are on Windows compile these functions */
#ifdef _WIN32
#include <string.h>
#include <assert.h>
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 <editline/readline.h>
#endif
int main(int argc, char const *argv[])


Loading…
Cancel
Save