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
a9c9fe3
..
bd053ee
100644
(file)
--- a/
lib/quotearg.c
+++ b/
lib/quotearg.c
@@
-1,5
+1,5
@@
/* quotearg.c - quote arguments for output
/* quotearg.c - quote arguments for output
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000
, 2001
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
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
@@
-21,6
+21,9
@@
# include <config.h>
#endif
# include <config.h>
#endif
+#if HAVE_STDDEF_H
+# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
+#endif
#include <sys/types.h>
#include <quotearg.h>
#include <xalloc.h>
#include <sys/types.h>
#include <quotearg.h>
#include <xalloc.h>
@@
-41,9
+44,15
@@
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
#ifndef UCHAR_MAX
# define UCHAR_MAX ((unsigned char) -1)
#endif
#ifndef UCHAR_MAX
# define UCHAR_MAX ((unsigned char) -1)
#endif
+#ifndef UINT_MAX
+# define UINT_MAX ((unsigned int) -1)
+#endif
#if HAVE_C_BACKSLASH_A
# define ALERT_CHAR '\a'
#if HAVE_C_BACKSLASH_A
# define ALERT_CHAR '\a'
@@
-60,16
+69,15
@@
#endif
#if HAVE_WCHAR_H
#endif
#if HAVE_WCHAR_H
+
+/* BSD/OS 4.1 wchar.h requires FILE and struct tm to be declared. */
+# include <stdio.h>
+# include <time.h>
+
# include <wchar.h>
#endif
# include <wchar.h>
#endif
-#if HAVE_MBRTOWC
-size_t mbrtowc ();
-# ifdef mbstate_t
-# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
-# define mbsinit(ps) 1
-# endif
-#else
+#if !HAVE_MBRTOWC
/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
other macros are defined only for documentation and to satisfy C
syntax. */
/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
other macros are defined only for documentation and to satisfy C
syntax. */
@@
-92,15
+100,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
{
@@
-534,28
+541,35
@@
quotearg_n_options (int n, char const *arg,
one small component of a "memory exhausted" message in slot 0. */
static char slot0[256];
static unsigned int nslots = 1;
one small component of a "memory exhausted" message in slot 0. */
static char slot0[256];
static unsigned int nslots = 1;
+ unsigned int n0 = n;
struct slotvec
{
size_t size;
char *val;
};
struct slotvec
{
size_t size;
char *val;
};
- static struct slotvec
const
slotvec0 = {sizeof slot0, slot0};
- static struct slotvec *slotvec =
(struct slotvec *)
&slotvec0;
+ static struct slotvec slotvec0 = {sizeof slot0, slot0};
+ static struct slotvec *slotvec = &slotvec0;
- if (nslots <= n)
+ if (n < 0)
+ abort ();
+
+ if (nslots <= n0)
{
{
- int n1 = n + 1;
- size_t s = n1 * sizeof (struct slotvec);
- if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
- abort ();
+ unsigned int n1 = n0 + 1;
+ size_t s = n1 * sizeof *slotvec;
+
+ if (SIZE_MAX / UINT_MAX <= sizeof *slotvec
+ && n1 != s / sizeof *slotvec)
+ xalloc_die ();
+
if (slotvec == &slotvec0)
{
if (slotvec == &slotvec0)
{
- slotvec = (struct slotvec *) xmalloc (sizeof
(struct slotvec)
);
+ slotvec = (struct slotvec *) xmalloc (sizeof
*slotvec
);
*slotvec = slotvec0;
}
slotvec = (struct slotvec *) xrealloc (slotvec, s);
*slotvec = slotvec0;
}
slotvec = (struct slotvec *) xrealloc (slotvec, s);
- memset (slotvec + nslots, 0, (n1 - nslots) * sizeof
(struct slotvec)
);
- nslots = n;
+ memset (slotvec + nslots, 0, (n1 - nslots) * sizeof
*slotvec
);
+ nslots = n
1
;
}
{
}
{
@@
-575,7
+589,7
@@
quotearg_n_options (int n, char const *arg,
}
char *
}
char *
-quotearg_n (
unsigned
int n, char const *arg)
+quotearg_n (int n, char const *arg)
{
return quotearg_n_options (n, arg, &default_quoting_options);
}
{
return quotearg_n_options (n, arg, &default_quoting_options);
}
@@
-587,7
+601,7
@@
quotearg (char const *arg)
}
char *
}
char *
-quotearg_n_style (
unsigned
int n, enum quoting_style s, char const *arg)
+quotearg_n_style (int n, enum quoting_style s, char const *arg)
{
struct quoting_options o;
o.style = s;
{
struct quoting_options o;
o.style = s;