Welcome to little lamb

Code » limb » commit 4e57787

loadopt: Don't error out on config file not found

author Olivier Brunel
2023-04-02 07:31:10 UTC
committer Olivier Brunel
2023-05-20 18:06:34 UTC
parent b3034cacbf77c0f492f8dee22cf44aca044aa28a

loadopt: Don't error out on config file not found

If the config file doesn't exist (ENOENT) simply silently continue on.
Only report an error when it can't be opened/read (e.g. EACCES).

src/liblimb/loadopt.h/loadopt.c +7 -3

diff --git a/src/liblimb/loadopt.h/loadopt.c b/src/liblimb/loadopt.h/loadopt.c
index f3b0505..aabbeb5 100644
--- a/src/liblimb/loadopt.h/loadopt.c
+++ b/src/liblimb/loadopt.h/loadopt.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
 /* SPDX-License-Identifier: GPL-2.0-only */
 #include <ctype.h>
+#include <errno.h>
 #include <limb/bytestr.h>
 #include <limb/djbunix.h>
 #include <limb/loadopt.h>
@@ -136,12 +137,15 @@ nextopt:
         /* prepend buffer with LF to make searching for section easier */
         if (!stralloc_catb(&ctx->sa, "\n", 1)
                 || !openslurpclose(&ctx->sa, file)) {
-            warnusys("read ", ESC, file, ESC);
             stralloc_free(&ctx->sa);
             ctx->state = STATE_CONFIG;
-            return LOADOPT_ERR_FILE;
+            if (errno != ENOENT) {
+                warnusys("read ", ESC, file, ESC);
+                return LOADOPT_ERR_FILE;
+            }
+        } else {
+            ctx->state = STATE_FILE;
         }
-        ctx->state = STATE_FILE;
     }
 
     /* file is read, position into the right section */