bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf-parse: Handle a PRIdMAX value of "qd" (for MacOS X 10.3).


From: Bruno Haible
Subject: Re: printf-parse: Handle a PRIdMAX value of "qd" (for MacOS X 10.3).
Date: Wed, 9 Jan 2008 02:17:56 +0100
User-agent: KMail/1.5.4

Hi Jim,

> Sure, it probably works, but adding support for the non-standard
> %qd specifier seems wrong.  Maybe it'd be better to make
> gt_INTTYPES_PRI declare such a PRIdMAX value invalid and to
> provide a replacement definition.

This doesn't work because PRIdMAX must also be understood by the native
printf (recall that some of the *printf functions might be implemented by
gnulib while some others might still refer to the libc function), and
these native printfs don't support "%lld".

>       printf-parse.c: handle a PRIdMAX value of "qd" (for MacOS X 10.3).

The same problem exists also on mingw, where PRIdMAX is "I64d".

Paul Eggert wrote:
> Another possibility (though this will require a bit more contortion,
> to get access PRIdMAX) is to change the test from:
>
>                   else if (*cp == 'q')
>
> to:
>
>                   else if (PRIdMAX[0] == 'q' && *cp == 'q')

I prefer a test that does not penalize unrelated platforms (_not_ assuming
advanced compiler optimizations).

I'm applying this:


2008-01-08  Jim Meyering  <address@hidden>
            Bruno Haible  <address@hidden>

        * lib/printf-parse.c (PRINTF_PARSE): Handle a size specifier "q"
        on MacOS X and a size specifier "I64" on mingw. Needed for PRIdMAX.
        Reported by Peter Fales in
        <http://lists.gnu.org/archive/html/bug-coreutils/2007-12/msg00148.html>.

*** lib/printf-parse.c.orig     2008-01-09 02:10:22.000000000 +0100
--- lib/printf-parse.c  2008-01-09 02:05:00.000000000 +0100
***************
*** 1,5 ****
  /* Formatted output to strings.
!    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
--- 1,5 ----
  /* Formatted output to strings.
!    Copyright (C) 1999-2000, 2002-2003, 2006-2008 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
***************
*** 392,397 ****
--- 392,435 ----
                        }
                      cp++;
                    }
+ #if defined __APPLE__ && defined __MACH__
+                 /* On MacOS X 10.3, PRIdMAX is defined as "qd".
+                    We cannot change it to "lld" because PRIdMAX must also
+                    be understood by the system's printf routines.  */
+                 else if (*cp == 'q')
+                   {
+                     if (64 / 8 > sizeof (long))
+                       {
+                         /* int64_t = long long */
+                         flags += 16;
+                       }
+                     else
+                       {
+                         /* int64_t = long */
+                         flags += 8;
+                       }
+                     cp++;
+                   }
+ #endif
+ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+                 /* On native Win32, PRIdMAX is defined as "I64d".
+                    We cannot change it to "lld" because PRIdMAX must also
+                    be understood by the system's printf routines.  */
+                 else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
+                   {
+                     if (64 / 8 > sizeof (long))
+                       {
+                         /* __int64 = long long */
+                         flags += 16;
+                       }
+                     else
+                       {
+                         /* __int64 = long */
+                         flags += 8;
+                       }
+                     cp += 3;
+                   }
+ #endif
                  else
                    break;
                }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]