Skip to content

Commit 9192371

Browse files
committed
fex2bin: call generate_bin() and write data out on success
1 parent 2abe140 commit 9192371

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

fex2bin.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ int main(int argc, char *argv[])
234234
const char *fn[] = {"stdin", "stdout"};
235235
struct script *script;
236236

237-
pr_info("WARNING: this tool is still not functional, sorry\n");
238-
239237
if (argc>1) {
240238
if (strcmp(argv[1],"-") == 0)
241239
; /* we are using stdin anyway */
@@ -262,11 +260,29 @@ int main(int argc, char *argv[])
262260

263261
if (parse_fex(in, fn[0], script)) {
264262
size_t sections, entries, bin_size;
263+
void *bin;
265264

266265
bin_size = calculate_bin_size(script, &sections, &entries);
267-
ret = 0;
266+
bin = calloc(1, bin_size);
267+
if (!bin)
268+
perror("malloc");
269+
else if (generate_bin(bin, bin_size, script, sections, entries)) {
270+
271+
while(bin_size) {
272+
ssize_t wc = write(out, bin, bin_size);
268273

269-
(void)bin_size;
274+
if (wc>0) {
275+
bin += wc;
276+
bin_size -= wc;
277+
} else if (wc < 0 && errno != EINTR) {
278+
pr_err("%s: write: %s\n", fn[2],
279+
strerror(errno));
280+
break;
281+
}
282+
}
283+
if (bin_size == 0)
284+
ret = 0;
285+
}
270286
}
271287

272288
script_delete(script);

script_bin.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,10 @@ size_t calculate_bin_size(struct script *script,
8787
bin_size);
8888
return bin_size;
8989
}
90-
#undef WORDS
90+
91+
int generate_bin(void *bin, size_t bin_size, struct script *script,
92+
size_t sections, size_t entries)
93+
{
94+
pr_err("bin generation not yet implemented\n");
95+
return 0;
96+
}

script_bin.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919

2020
size_t calculate_bin_size(struct script *script,
2121
size_t *sections, size_t *entries);
22+
23+
int generate_bin(void *bin, size_t bin_size, struct script *script,
24+
size_t sections, size_t entries);
2225
#endif

0 commit comments

Comments
 (0)