projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Assume 'long double' exists.
[gnulib.git]
/
lib
/
printf-parse.c
diff --git
a/lib/printf-parse.c
b/lib/printf-parse.c
index
b386b7b
..
7de0b9f
100644
(file)
--- a/
lib/printf-parse.c
+++ b/
lib/printf-parse.c
@@
-1,5
+1,5
@@
/* Formatted output to strings.
/* Formatted output to strings.
- Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 1999-2000, 2002-2003
, 2006-2007
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
@@
-13,11
+13,9
@@
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
- Inc., 5
9 Temple Place - Suite 330, Boston, MA 02111-1307
, USA. */
+ Inc., 5
1 Franklin Street, Fifth Floor, Boston, MA 02110-1301
, USA. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
/* Specification. */
#if WIDE_CHAR_VERSION
/* Specification. */
#if WIDE_CHAR_VERSION
@@
-30,12
+28,16
@@
#include <stddef.h>
/* Get intmax_t. */
#include <stddef.h>
/* Get intmax_t. */
-#if HAVE_STDINT_H_WITH_UINTMAX
+#ifdef IN_LIBINTL
+# if HAVE_STDINT_H_WITH_UINTMAX
+# include <stdint.h>
+# endif
+# if HAVE_INTTYPES_H_WITH_UINTMAX
+# include <inttypes.h>
+# endif
+#else
# include <stdint.h>
#endif
# include <stdint.h>
#endif
-#if HAVE_INTTYPES_H_WITH_UINTMAX
-# include <inttypes.h>
-#endif
/* malloc(), realloc(), free(). */
#include <stdlib.h>
/* malloc(), realloc(), free(). */
#include <stdlib.h>
@@
-70,7
+72,7
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
d->count = 0;
d_allocated = 1;
d->count = 0;
d_allocated = 1;
- d->dir = malloc (d_allocated * sizeof (DIRECTIVE));
+ d->dir =
(DIRECTIVE *)
malloc (d_allocated * sizeof (DIRECTIVE));
if (d->dir == NULL)
/* Out of memory. */
return -1;
if (d->dir == NULL)
/* Out of memory. */
return -1;
@@
-94,9
+96,9
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto error; \
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto error; \
- memory = (a
->arg
\
-
? realloc (a->arg, memory_size)
\
-
: malloc (memory_size));
\
+ memory = (a
rgument *) (a->arg
\
+
? realloc (a->arg, memory_size)
\
+
: malloc (memory_size));
\
if (memory == NULL) \
/* Out of memory. */ \
goto error; \
if (memory == NULL) \
/* Out of memory. */ \
goto error; \
@@
-328,7
+330,6
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
flags += 8;
cp++;
}
flags += 8;
cp++;
}
-#ifdef HAVE_INTMAX_T
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
@@
-343,7
+344,6
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
}
cp++;
}
}
cp++;
}
-#endif
else if (*cp == 'z' || *cp == 'Z')
{
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
else if (*cp == 'z' || *cp == 'Z')
{
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
@@
-384,11
+384,14
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
switch (c)
{
case 'd': case 'i':
switch (c)
{
case 'd': case 'i':
-#ifdef HAVE_LONG_LONG
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_LONGLONGINT;
else
#endif
if (flags >= 16 || (flags & 4))
type = TYPE_LONGLONGINT;
else
#endif
+ /* If 'long long' exists and is the same as 'long', we parse
+ "lld" into TYPE_LONGINT. */
if (flags >= 8)
type = TYPE_LONGINT;
else if (flags & 2)
if (flags >= 8)
type = TYPE_LONGINT;
else if (flags & 2)
@@
-399,11
+402,14
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
type = TYPE_INT;
break;
case 'o': case 'u': case 'x': case 'X':
type = TYPE_INT;
break;
case 'o': case 'u': case 'x': case 'X':
-#ifdef HAVE_LONG_LONG
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_ULONGLONGINT;
else
#endif
if (flags >= 16 || (flags & 4))
type = TYPE_ULONGLONGINT;
else
#endif
+ /* If 'unsigned long long' exists and is the same as
+ 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
if (flags >= 8)
type = TYPE_ULONGINT;
else if (flags & 2)
if (flags >= 8)
type = TYPE_ULONGINT;
else if (flags & 2)
@@
-415,16
+421,14
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
break;
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
case 'a': case 'A':
break;
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
case 'a': case 'A':
-#ifdef HAVE_LONG_DOUBLE
if (flags >= 16 || (flags & 4))
type = TYPE_LONGDOUBLE;
else
if (flags >= 16 || (flags & 4))
type = TYPE_LONGDOUBLE;
else
-#endif
- type = TYPE_DOUBLE;
+ type = TYPE_DOUBLE;
break;
case 'c':
if (flags >= 8)
break;
case 'c':
if (flags >= 8)
-#if
def
HAVE_WINT_T
+#if HAVE_WINT_T
type = TYPE_WIDE_CHAR;
#else
goto error;
type = TYPE_WIDE_CHAR;
#else
goto error;
@@
-432,7
+436,7
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
else
type = TYPE_CHAR;
break;
else
type = TYPE_CHAR;
break;
-#if
def
HAVE_WINT_T
+#if HAVE_WINT_T
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
@@
-440,7
+444,7
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
#endif
case 's':
if (flags >= 8)
#endif
case 's':
if (flags >= 8)
-#if
def
HAVE_WCHAR_T
+#if HAVE_WCHAR_T
type = TYPE_WIDE_STRING;
#else
goto error;
type = TYPE_WIDE_STRING;
#else
goto error;
@@
-448,7
+452,7
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
else
type = TYPE_STRING;
break;
else
type = TYPE_STRING;
break;
-#if
def
HAVE_WCHAR_T
+#if HAVE_WCHAR_T
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
@@
-458,11
+462,14
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
type = TYPE_POINTER;
break;
case 'n':
type = TYPE_POINTER;
break;
case 'n':
-#ifdef HAVE_LONG_LONG
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_COUNT_LONGLONGINT_POINTER;
else
#endif
if (flags >= 16 || (flags & 4))
type = TYPE_COUNT_LONGLONGINT_POINTER;
else
#endif
+ /* If 'long long' exists and is the same as 'long', we parse
+ "lln" into TYPE_COUNT_LONGINT_POINTER. */
if (flags >= 8)
type = TYPE_COUNT_LONGINT_POINTER;
else if (flags & 2)
if (flags >= 8)
type = TYPE_COUNT_LONGINT_POINTER;
else if (flags & 2)
@@
-508,7
+515,7
@@
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto error;
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto error;
- memory = realloc (d->dir, memory_size);
+ memory =
(DIRECTIVE *)
realloc (d->dir, memory_size);
if (memory == NULL)
/* Out of memory. */
goto error;
if (memory == NULL)
/* Out of memory. */
goto error;