summaryrefslogtreecommitdiffstats
path: root/lib/quotearg.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/quotearg.c')
-rw-r--r--lib/quotearg.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 975bd61..847101e 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -1,6 +1,6 @@
/* quotearg.c - quote arguments for output
- Copyright (C) 1998-2002, 2004-2023 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2004-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -41,8 +41,8 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <uchar.h>
#include <wchar.h>
-#include <wctype.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@ -531,12 +531,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
case '<':
case '=': /* sometimes special in 0th or (with "set -k") later args */
case '>': case '[':
- case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
+ case '^': /* special in old /bin/sh, e.g., Solaris 10 */
case '`': case '|':
- /* A shell special character. In theory, '$' and '`' could
- be the first bytes of multibyte characters, which means
- we should check them with mbrtowc, but in practice this
- doesn't happen so it's not worth worrying about. */
+ /* A shell special character. */
if (quoting_style == shell_always_quoting_style
&& elide_outer_quotes)
goto force_outer_quoting_style;
@@ -611,18 +608,18 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
else
{
mbstate_t mbstate;
- memset (&mbstate, 0, sizeof mbstate);
+ mbszero (&mbstate);
m = 0;
printable = true;
if (argsize == SIZE_MAX)
argsize = strlen (arg);
- do
+ for (;;)
{
- wchar_t w;
- size_t bytes = mbrtowc (&w, &arg[i + m],
- argsize - (i + m), &mbstate);
+ char32_t w;
+ size_t bytes = mbrtoc32 (&w, &arg[i + m],
+ argsize - (i + m), &mbstate);
if (bytes == 0)
break;
else if (bytes == (size_t) -1)
@@ -639,6 +636,10 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
}
else
{
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (bytes == (size_t) -3)
+ bytes = 0;
+ #endif
/* Work around a bug with older shells that "see" a '\'
that is really the 2nd byte of a multibyte character.
In practice the problem is limited to ASCII
@@ -659,12 +660,15 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
}
}
- if (! iswprint (w))
+ if (! c32isprint (w))
printable = false;
m += bytes;
}
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (mbsinit (&mbstate))
+ #endif
+ break;
}
- while (! mbsinit (&mbstate));
}
c_and_shell_quote_compat = printable;