From: Pádraig Brady
Date: Fri, 31 Jul 2026 13:12:37 +0000 (+0100)
Subject: maint: ls,stat: factor out getenv_quoting_style
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9ed8168ac23b45d18cb4107be49051a31a145cb;p=thirdparty%2Fcoreutils.git
maint: ls,stat: factor out getenv_quoting_style
* 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.
---
diff --git a/src/ls.c b/src/ls.c
index 466715be47..3748a127bc 100644
--- 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. */
diff --git a/src/stat.c b/src/stat.c
index 60397d3686..ff149a76ae 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -55,10 +55,10 @@
#include
#include
+#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
diff --git a/src/system.h b/src/system.h
index e96127d41f..7efc78972d 100644
--- a/src/system.h
+++ b/src/system.h
@@ -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,