bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/9] builtins/source: add the -l|--library options


From: Matheus Afonso Martins Moreira
Subject: [PATCH 7/9] builtins/source: add the -l|--library options
Date: Sun, 5 May 2024 06:55:00 -0300

Passing these options to the source builtin
enables library loading mode which restricts
its search path to the directories defined by
the BASH_LIBRARIES_PATH variable.

Signed-off-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
---
 builtins/source.def | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtins/source.def b/builtins/source.def
index 0809c19d..8ca9631f 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -131,9 +131,28 @@ source_builtin (list)
      WORD_LIST *list;
 {
   char *filename, *x;
+  int opt, library_mode = 0;
 
-  if (no_options (list))
-    return (EX_USAGE);
+  struct option_conversion conversions[] = {
+    { "--library", 'l'  },
+    { NULL,        '\0' },
+  };
+
+  shorten_long_options (list, conversions);
+  reset_internal_getopt ();
+  while ((opt = internal_getopt (list, "l")) != -1)
+    {
+      switch (opt)
+       {
+       case 'l':
+          library_mode = 1;
+         break;
+       CASE_HELPOPT;
+       default:
+         builtin_usage ();
+         return (EX_USAGE);
+       }
+    }
   list = loptend;
 
   if (list == 0)
-- 
2.44.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]