* [PATCH olang] cli: add libc error handling
@ 2024-09-17 15:14 Carlos Maniero
2024-09-17 15:15 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-17 15:17 ` [PATCH olang] cli: add libc error handling Johnny Richard
0 siblings, 2 replies; 3+ messages in thread
From: Carlos Maniero @ 2024-09-17 15:14 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero
The application was ignoring libc functions result and not handling
possible errors. This effort also makes the application POSIX complaint.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
src/main.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/main.c b/src/main.c
index e16695b..030f34c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -164,14 +164,24 @@ handle_codegen_linux(cli_opts_t *opts)
char command[512];
sprintf(command, "%s/bin/as %s -o " SV_FMT ".o", opts->sysroot, asm_file, SV_ARG(opts->output_bin));
- system(command);
+
+ int exit_code = system(command);
+
+ if (exit_code != 0) {
+ exit(exit_code);
+ }
sprintf(command,
"%s/bin/ld " SV_FMT ".o -o " SV_FMT "",
opts->sysroot,
SV_ARG(opts->output_bin),
SV_ARG(opts->output_bin));
- system(command);
+
+ exit_code = system(command);
+
+ if (exit_code != 0) {
+ exit(exit_code);
+ }
if (!(opts->options & CLI_OPT_SAVE_TEMPS)) {
char output_file[256];
@@ -211,7 +221,13 @@ read_entire_file(char *file_path, arena_t *arena)
exit(EXIT_FAILURE);
}
- fread(file_content.chars, 1, file_content.size, stream);
+ size_t read_bytes = fread(file_content.chars, 1, file_content.size, stream);
+
+ if (read_bytes != file_content.size) {
+ fprintf(stderr, "error: failed to read all file bytes %s\n", file_path);
+ exit(EXIT_FAILURE);
+ }
+
fclose(stream);
return file_content;
base-commit: 5802359caf011c960b455dcda7ce10ea794b0ea1
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-17 15:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-17 15:14 [PATCH olang] cli: add libc error handling Carlos Maniero
2024-09-17 15:15 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-17 15:17 ` [PATCH olang] cli: add libc error handling Johnny Richard
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox