aboutsummaryrefslogtreecommitdiffhomepage
path: root/config.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-08-03 18:42:39 +0200
committercbdev <cb@cbcdn.com>2019-08-03 18:42:39 +0200
commit20a6882a063404858588596bd3f12bdd9e53460a (patch)
treec13ee23aec08ac3c29a1ff9efe2e429d87041239 /config.c
parentbbeade8898200a8024169ece30c620016fd5eaf1 (diff)
downloadmidimonster-20a6882a063404858588596bd3f12bdd9e53460a.tar.gz
midimonster-20a6882a063404858588596bd3f12bdd9e53460a.tar.bz2
midimonster-20a6882a063404858588596bd3f12bdd9e53460a.zip
Windows build compatiblity
Diffstat (limited to 'config.c')
-rw-r--r--config.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/config.c b/config.c
index 6d5fd16..93fb56d 100644
--- a/config.c
+++ b/config.c
@@ -20,6 +20,62 @@ typedef enum {
static backend* current_backend = NULL;
static instance* current_instance = NULL;
+#ifdef _WIN32
+#define GETLINE_BUFFER 4096
+
+static ssize_t getline(char** line, size_t* alloc, FILE* stream){
+ size_t bytes_read = 0;
+ char c;
+ //sanity checks
+ if(!line || !alloc || !stream){
+ return -1;
+ }
+
+ //allocate buffer if none provided
+ if(!*line || !*alloc){
+ *alloc = GETLINE_BUFFER;
+ *line = calloc(GETLINE_BUFFER, sizeof(char));
+ if(!*line){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return -1;
+ }
+ }
+
+ if(feof(stream)){
+ return -1;
+ }
+
+ for(c = fgetc(stream); 1; c = fgetc(stream)){
+ //end of buffer, resize
+ if(bytes_read == (*alloc) - 1){
+ *alloc += GETLINE_BUFFER;
+ *line = realloc(*line, (*alloc) * sizeof(char));
+ if(!*line){
+ fprintf(stderr, "Failed to allocate memory\n");
+ return -1;
+ }
+ }
+
+ //store character
+ (*line)[bytes_read] = c;
+
+ //end of line
+ if(feof(stream) || c == '\n'){
+ //terminate string
+ (*line)[bytes_read + 1] = 0;
+ return bytes_read;
+ }
+
+ //input broken
+ if(ferror(stream) || c < 0){
+ return -1;
+ }
+
+ bytes_read++;
+ }
+}
+#endif
+
static char* config_trim_line(char* in){
ssize_t n;
//trim front