]> git.leonardobizzoni.com Git - CBuild/commitdiff
Print executable name on child process creation failure
authorLeonardoBizzoni <leo2002714@gmail.com>
Thu, 25 Sep 2025 16:22:14 +0000 (18:22 +0200)
committerLeonardoBizzoni <leo2002714@gmail.com>
Thu, 25 Sep 2025 16:22:14 +0000 (18:22 +0200)
cbuild.h
examples/02-async-commands/build.c

index 500b214af00299eacffc8071d491157ad841f7ed..2fbce3a71f7ec39f8e1f5ed09e991ef75266bb73 100644 (file)
--- a/cbuild.h
+++ b/cbuild.h
@@ -580,8 +580,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) {
                   FORMAT_MESSAGE_IGNORE_INSERTS,
                   0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                   (LPTSTR)&lpMsgBuf, 0, 0);
-    cb_println(CB_LogLevel_Error, "Child process creation failed with error %u: %s",
-               error, lpMsgBuf);
+    cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %u: %s",
+               cmd->values[0], error, lpMsgBuf);
     exit(-1);
   }
 
@@ -590,8 +590,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) {
 #else
   res.handle = fork();
   if (res.handle < 0) {
-    cb_println(CB_LogLevel_Error, "Child process creation failed with error %d: %s\n",
-               errno, strerror(errno));
+    cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %d: %s\n",
+               cmd->values[0], errno, strerror(errno));
     exit(-1);
   } else if (!res.handle) {
     if (args.stdout) { dup2(args.stdout, STDOUT_FILENO); }
@@ -605,8 +605,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) {
     cb_cmd_append_dyn(&_cmd, cmd->values, cmd->count);
     cb_cmd_push(&_cmd, 0);
     if (execvp(_cmd.values[0], _cmd.values) < 0) {
-      cb_println(CB_LogLevel_Error, "Child process creation failed with error %d: %s\n",
-                 errno, strerror(errno));
+      cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %d: %s\n",
+                 cmd->values[0], errno, strerror(errno));
       exit(-1);
     }
     // NOTE(lb): unreachable, execvp only returns on error.
index 2256e7f1ec6385342e38d9f7d34fd632d65d8943..02aa16e17753a7b3ea7bb74f6af69e4cbdf7ba94 100644 (file)
@@ -5,12 +5,19 @@ int main(int argc, char **argv) {
 
   CB_Cmd cmd = {};
   CB_ProcessList procs = {};
+#if OS_WINDOWS
+  cb_cmd_append(&cmd, "cmd.exe", "/C", "dir");
+  cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true));
+  cb_cmd_append(&cmd, "cmd.exe", "/C", "dir", "C:\\");
+  cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true));
+#else
   cb_cmd_append(&cmd, "ls", "-lah", ".");
   cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true));
   cb_cmd_append(&cmd, "ls", "-lah", "/");
   cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true));
   cb_cmd_append(&cmd, "pwd");
   cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true));
+#endif
 
   cb_proclist_wait(&procs);
 }