summaryrefslogtreecommitdiff
path: root/lib/printf-parse.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-03-01 10:41:48 +0100
committerJim Meyering <jim@meyering.net>2007-03-01 10:41:48 +0100
commitb3b6f52fadfbab0277153b9142251989e8e635d4 (patch)
tree0358f8ca641cef8ef33bd16bef42e1cfc754d6c3 /lib/printf-parse.c
parentf6f2846bd8aba934fd823e71d1de66f0d2806756 (diff)
downloadcoreutils-b3b6f52fadfbab0277153b9142251989e8e635d4.tar.xz
Merge in changes from gnulib:
* vasnprintf.c: Add a comment explaining why coreutils has its own version of this file. Include <stdint.h>. (SIZE_MAX): Remove definition (now, stdint.h covers that). (EOVERFLOW): Remove definition (now done via the eoverflow module). Update some #ifdef to #if. Use HAVE_LONG_LONG_INT, not HAVE_LONG_LONG. * printf-parse.c: Likewise.
Diffstat (limited to 'lib/printf-parse.c')
-rw-r--r--lib/printf-parse.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/printf-parse.c b/lib/printf-parse.c
index f8e0ceda5..9493403eb 100644
--- a/lib/printf-parse.c
+++ b/lib/printf-parse.c
@@ -1,5 +1,8 @@
/* Formatted output to strings.
- Copyright (C) 1999-2000, 2002-2004, 2006 Free Software Foundation, Inc.
+ This file is intended to provide exactly the same functionality
+ as the version in gnulib, but without the need for the xsize module.
+
+ 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
@@ -27,21 +30,12 @@
/* Get size_t, NULL. */
#include <stddef.h>
-/* Get intmax_t. */
-#if HAVE_STDINT_H_WITH_UINTMAX
-# include <stdint.h>
-#endif
-#if HAVE_INTTYPES_H_WITH_UINTMAX
-# include <inttypes.h>
-#endif
+/* Get intmax_t, SIZE_MAX. */
+#include <stdint.h>
/* malloc(), realloc(), free(). */
#include <stdlib.h>
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
#if WIDE_CHAR_VERSION
# define PRINTF_PARSE wprintf_parse
# define CHAR_T wchar_t
@@ -329,7 +323,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
flags += 8;
cp++;
}
-#ifdef HAVE_INTMAX_T
+#if HAVE_INTMAX_T
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
@@ -385,11 +379,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
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 '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)
@@ -400,11 +397,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
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 '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)
@@ -416,7 +416,7 @@ 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':
-#ifdef HAVE_LONG_DOUBLE
+#if HAVE_LONG_DOUBLE
if (flags >= 16 || (flags & 4))
type = TYPE_LONGDOUBLE;
else
@@ -425,7 +425,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
break;
case 'c':
if (flags >= 8)
-#ifdef HAVE_WINT_T
+#if HAVE_WINT_T
type = TYPE_WIDE_CHAR;
#else
goto error;
@@ -433,7 +433,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
else
type = TYPE_CHAR;
break;
-#ifdef HAVE_WINT_T
+#if HAVE_WINT_T
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
@@ -441,7 +441,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
#endif
case 's':
if (flags >= 8)
-#ifdef HAVE_WCHAR_T
+#if HAVE_WCHAR_T
type = TYPE_WIDE_STRING;
#else
goto error;
@@ -449,7 +449,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
else
type = TYPE_STRING;
break;
-#ifdef HAVE_WCHAR_T
+#if HAVE_WCHAR_T
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
@@ -459,11 +459,14 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
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 '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)