public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [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

* [olang/patches/.build.yml] build success
  2024-09-17 15:14 [PATCH olang] cli: add libc error handling Carlos Maniero
@ 2024-09-17 15:15 ` builds.sr.ht
  2024-09-17 15:17 ` [PATCH olang] cli: add libc error handling Johnny Richard
  1 sibling, 0 replies; 3+ messages in thread
From: builds.sr.ht @ 2024-09-17 15:15 UTC (permalink / raw)
  To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel

olang/patches/.build.yml: SUCCESS in 20s

[cli: add libc error handling][0] from [Carlos Maniero][1]

[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/55079
[1]: mailto:carlos@maniero.me

✓ #1330161 SUCCESS olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1330161

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH olang] cli: add libc error handling
  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 ` Johnny Richard
  1 sibling, 0 replies; 3+ messages in thread
From: Johnny Richard @ 2024-09-17 15:17 UTC (permalink / raw)
  To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel

Thanks!

Build started: https://builds.sr.ht/~johnnyrichard/job/1330163

To git.sr.ht:~johnnyrichard/olang
   5802359..14ff487  HEAD -> main


^ 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