projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[gnulib.git]
/
lib
/
quotearg.c
diff --git
a/lib/quotearg.c
b/lib/quotearg.c
index
47152bc
..
d5fbc9e
100644
(file)
--- a/
lib/quotearg.c
+++ b/
lib/quotearg.c
@@
-59,11
+59,12
@@
# include <string.h>
#endif
# include <string.h>
#endif
-#if HAVE_MBRTOWC && 1 < MB_LEN_MAX
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
+#if HAVE_MBRTOWC
size_t mbrtowc ();
size_t mbrtowc ();
-# if HAVE_WCHAR_H
-# include <wchar.h>
-# endif
# ifdef mbstate_t
# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
# define mbsinit(ps) 1
# ifdef mbstate_t
# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
# define mbsinit(ps) 1
@@
-91,15
+92,14
@@
size_t mbrtowc ();
#define INT_BITS (sizeof (int) * CHAR_BIT)
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
#define INT_BITS (sizeof (int) * CHAR_BIT)
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
-/* Undefine to protect against the definition in wctype.h of solaris2.6. */
-# undef ISASCII
-# define ISASCII(c) 1
+# define IN_CTYPE_DOMAIN(c) 1
#else
#else
-# define I
SASCII(c) isascii
(c)
+# define I
N_CTYPE_DOMAIN(c) isascii
(c)
#endif
#endif
+
/* Undefine to protect against the definition in wctype.h of solaris2.6. */
#undef ISPRINT
/* Undefine to protect against the definition in wctype.h of solaris2.6. */
#undef ISPRINT
-#define ISPRINT(c) (I
SASCII
(c) && isprint (c))
+#define ISPRINT(c) (I
N_CTYPE_DOMAIN
(c) && isprint (c))
struct quoting_options
{
struct quoting_options
{
@@
-529,12
+529,17
@@
static char *
quotearg_n_options (int n, char const *arg,
struct quoting_options const *options)
{
quotearg_n_options (int n, char const *arg,
struct quoting_options const *options)
{
- static unsigned int nslots;
- static struct slotvec
+ /* Preallocate a slot 0 buffer, so that the caller can always quote
+ one small component of a "memory exhausted" message in slot 0. */
+ static char slot0[256];
+ static unsigned int nslots = 1;
+ struct slotvec
{
size_t size;
char *val;
{
size_t size;
char *val;
- } *slotvec;
+ };
+ static struct slotvec slotvec0 = {sizeof slot0, slot0};
+ static struct slotvec *slotvec = &slotvec0;
if (nslots <= n)
{
if (nslots <= n)
{
@@
-542,6
+547,11
@@
quotearg_n_options (int n, char const *arg,
size_t s = n1 * sizeof (struct slotvec);
if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
abort ();
size_t s = n1 * sizeof (struct slotvec);
if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
abort ();
+ if (slotvec == &slotvec0)
+ {
+ slotvec = (struct slotvec *) xmalloc (sizeof (struct slotvec));
+ *slotvec = slotvec0;
+ }
slotvec = (struct slotvec *) xrealloc (slotvec, s);
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
nslots = n;
slotvec = (struct slotvec *) xrealloc (slotvec, s);
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
nslots = n;
@@
-555,7
+565,7
@@
quotearg_n_options (int n, char const *arg,
if (size <= qsize)
{
slotvec[n].size = size = qsize + 1;
if (size <= qsize)
{
slotvec[n].size = size = qsize + 1;
- slotvec[n].val = val = xrealloc (val, size);
+ slotvec[n].val = val = xrealloc (val
== slot0 ? 0 : val
, size);
quotearg_buffer (val, size, arg, (size_t) -1, options);
}
quotearg_buffer (val, size, arg, (size_t) -1, options);
}