summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-15 15:11:14 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commit17885ed3758096f677a5f2f2c73e07e5ba926388 (patch)
treec9fbb99b3a13383cc6ca4d1ada8f569153356f84
parent1d7e3d0b713371fc5c8ebd805a9679bbd7a416bb (diff)
eolian gen2: add file read
-rw-r--r--src/bin/eolian2/main.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bin/eolian2/main.c b/src/bin/eolian2/main.c
index aa3da0b70f..d8d945cc85 100644
--- a/src/bin/eolian2/main.c
+++ b/src/bin/eolian2/main.c
@@ -161,6 +161,46 @@ end:
161 return fret; 161 return fret;
162} 162}
163 163
164static Eina_Strbuf *
165_read_file(const char *fname)
166{
167 FILE *f = fopen(fname, "rb");
168 if (!f)
169 return NULL;
170
171 fseek(f, 0, SEEK_END);
172 long fs = ftell(f);
173 if (fs < 0)
174 {
175 fprintf(stderr, "eolian: could not get length of '%s'\n", fname);
176 fclose(f);
177 return NULL;
178 }
179 fseek(f, 0, SEEK_SET);
180
181 char *cont = malloc(fs + 1);
182 if (!cont)
183 {
184 fprintf(stderr, "eolian: could not allocate memory for '%s'\n", fname);
185 fclose(f);
186 return NULL;
187 }
188
189 long as = fread(cont, 1, fs, f);
190 if (as != fs)
191 {
192 fprintf(stderr, "eolian: could not read %ld bytes from '%s' (got %ld)\n",
193 fs, fname, as);
194 free(cont);
195 fclose(f);
196 return NULL;
197 }
198
199 cont[fs] = '\0';
200 fclose(f);
201 return eina_strbuf_manage_new_length(cont, fs);
202}
203
164static Eina_Bool 204static Eina_Bool
165_write_header(const char *ofname, const char *ifname, Eina_Bool legacy) 205_write_header(const char *ofname, const char *ifname, Eina_Bool legacy)
166{ 206{