[PATCH v3 3/6] posix: Introduce a convenience function to translate the option name

Vivien Kraus vivien@planete-kraus.eu
Sat May 31 21:14:46 GMT 2025


This is useful when the translation will be more complex than gettext.
---
 posix/getopt.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/posix/getopt.c b/posix/getopt.c
index bcf2203faf..451dfe8c0e 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -182,6 +182,12 @@ exchange (char **argv, struct _getopt_data *d)
   d->__last_nonopt = d->optind;
 }
 
+static const char *
+translate_option_name (const char *long_option_name)
+{
+  return gettext (long_option_name);
+}
+
 /* Return 1 iff a translation for opt_name has been found and it
    matches the substring from argument, length argument_length.
 */
@@ -189,7 +195,7 @@ static const int
 match_translated_option_name (const char *argument, size_t argument_length,
                               const char *opt_name)
 {
-  const char *translated = gettext (opt_name);
+  const char *translated = translate_option_name (opt_name);
   return (!strncmp (translated, argument, argument_length)
           && argument_length == strlen (translated));
 }
@@ -361,7 +367,7 @@ process_long_option (int argc, char **argv, const char *optstring,
   /* We have found a matching long option.  Consume it.  */
   d->optind++;
   d->__nextchar = NULL;
-  translated_option_name = gettext (pfound->name);
+  translated_option_name = translate_option_name (pfound->name);
   if (*nameend)
     {
       /* Don't test has_arg with >, because some C compilers don't
-- 
2.49.0



More information about the Libc-alpha mailing list