]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: ls,stat: factor out getenv_quoting_style
authorPádraig Brady <P@draigBrady.com>
Fri, 31 Jul 2026 13:12:37 +0000 (14:12 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 1 Aug 2026 11:38:28 +0000 (12:38 +0100)
* src/system.h (getenv_quoting_style): Move here from ls.c and stat.c.
* src/ls.c (getenv_quoting_style): Remove.
* src/stat.c (getenv_quoting_style): Remove.  Ensure ARGMATCH is
defined for system.h.

src/ls.c
src/stat.c
src/system.h

index 466715be47eb32acfed98ccd95e2bd37ddba5edd..3748a127bcf182d434a9d2ff9b09ad9bcbac84fd 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -306,8 +306,6 @@ static void queue_directory (char const *name, char const *realname,
 static void sort_files (void);
 static void parse_ls_color (void);
 
-static int getenv_quoting_style (void);
-
 static size_t quote_name_width (char const *name,
                                 struct quoting_options const *options,
                                 int needs_general_quoting);
@@ -2896,27 +2894,6 @@ parse_ls_color (void)
     color_symlink_as_referent = true;
 }
 
-/* Return the quoting style specified by the environment variable
-   QUOTING_STYLE if set and valid, -1 otherwise.  */
-
-static int
-getenv_quoting_style (void)
-{
-  char const *q_style = getenv ("QUOTING_STYLE");
-  if (!q_style)
-    return -1;
-  int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
-  if (i < 0)
-    {
-      error (0, 0,
-             _("ignoring invalid value"
-               " of environment variable QUOTING_STYLE: %s"),
-             quote (q_style));
-      return -1;
-    }
-  return quoting_style_vals[i];
-}
-
 /* Set the exit status to report a failure.  If SERIOUS, it is a
    serious failure; otherwise, it is merely a minor problem.  */
 
index 60397d3686569375bbe8e9b533e10bf6332b7550..ff149a76aec10abd5de25521e57331b4f5cb2c3e 100644 (file)
 #include <selinux/selinux.h>
 #include <getopt.h>
 
+#include "argmatch.h"  /* argmatch($QUOTING_STYLE).  */
 #include "system.h"
 
 #include "areadlink.h"
-#include "argmatch.h"
 #include "c-ctype.h"
 #include "file-type.h"
 #include "filemode.h"
@@ -855,26 +855,6 @@ out_file_context (char *pformat, size_t prefix_len, char const *filename)
   return fail;
 }
 
-/* Return the quoting style specified by the environment variable
-   QUOTING_STYLE if set and valid, -1 otherwise.  */
-
-static int
-getenv_quoting_style (void)
-{
-  char const *q_style = getenv ("QUOTING_STYLE");
-  if (!q_style)
-    return -1;
-
-  int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
-  if (i < 0)
-    {
-      error (0, 0, _("ignoring invalid value of environment "
-                     "variable QUOTING_STYLE: %s"), quote (q_style));
-      return -1;
-    }
-  return quoting_style_vals[i];
-}
-
 /* Set the quoting style once it is needed.  */
 static void
 initialize_quoting_style (void)
@@ -888,9 +868,6 @@ initialize_quoting_style (void)
     }
 }
 
-/* Equivalent to quotearg(), but explicit to avoid syntax checks.  */
-#define quoteN(x) quotearg_style (get_quoting_style (NULL), x)
-
 /* Print statfs info.  Return zero upon success, nonzero upon failure.  */
 NODISCARD
 static bool
index e96127d41f8137adbae1f50ae0517ee5ab0799c3..7efc78972d2b3cb06865682f3767fe63ff0f579d 100644 (file)
@@ -1002,8 +1002,30 @@ is_ENOTSUP (int err)
 #define quoteaf_n(n, arg) \
   quotearg_n_style (n, shell_escape_always_quoting_style, arg)
 
+/* Equivalent to quotearg(), but explicit to avoid syntax checks.  */
+#define quoteN(x) quotearg_style (get_quoting_style (NULL), x)
+
+#ifdef ARGMATCH
+/* Return the quoting style specified by the environment variable
+   QUOTING_STYLE if set and valid, -1 otherwise.  */
+static inline int
+getenv_quoting_style (void)
+{
+  char const *q_style = getenv ("QUOTING_STYLE");
+  if (!q_style)
+    return -1;
+
+  int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
+  if (i < 0)
+    {
+      error (0, 0, _("ignoring invalid value of environment "
+                     "variable QUOTING_STYLE: %s"), quote (q_style));
+      return -1;
+    }
+  return quoting_style_vals[i];
+}
+
 /* Used instead of XARGMATCH() to provide a custom error message.  */
-#ifdef XARGMATCH
 static inline ptrdiff_t
 x_timestyle_match (char const * style, bool allow_posix,
                    char const *const * timestyle_args,