From 17885ed3758096f677a5f2f2c73e07e5ba926388 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 15 Sep 2016 15:11:14 +0200 Subject: [PATCH] eolian gen2: add file read --- src/bin/eolian2/main.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/bin/eolian2/main.c b/src/bin/eolian2/main.c index aa3da0b..d8d945c 100644 --- a/src/bin/eolian2/main.c +++ b/src/bin/eolian2/main.c @@ -161,6 +161,46 @@ end: return fret; } +static Eina_Strbuf * +_read_file(const char *fname) +{ + FILE *f = fopen(fname, "rb"); + if (!f) + return NULL; + + fseek(f, 0, SEEK_END); + long fs = ftell(f); + if (fs < 0) + { + fprintf(stderr, "eolian: could not get length of '%s'\n", fname); + fclose(f); + return NULL; + } + fseek(f, 0, SEEK_SET); + + char *cont = malloc(fs + 1); + if (!cont) + { + fprintf(stderr, "eolian: could not allocate memory for '%s'\n", fname); + fclose(f); + return NULL; + } + + long as = fread(cont, 1, fs, f); + if (as != fs) + { + fprintf(stderr, "eolian: could not read %ld bytes from '%s' (got %ld)\n", + fs, fname, as); + free(cont); + fclose(f); + return NULL; + } + + cont[fs] = '\0'; + fclose(f); + return eina_strbuf_manage_new_length(cont, fs); +} + static Eina_Bool _write_header(const char *ofname, const char *ifname, Eina_Bool legacy) { -- 2.7.4