This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Support %Lx, %Lu, %Ld in _bfd_error_handler format
On Thu, Jul 06, 2017 at 07:36:37AM -0700, H.J. Lu wrote:
> On Thu, Jul 6, 2017 at 7:27 AM, Alan Modra <amodra@gmail.com> wrote:
> > Thanks. Hmm, maybe "L" should be changed to "ll" for long long too.
>
> On Linux, L == l:
>
> L A following a, A, e, E, f, F, g, or G conversion corresponds to
> a long double argument. (C99 allows %LF, but SUSv2 does not.)
> This is a synonym for ll.
Yes, but http://www.unix.com/man-page/posix/3p/fprintf/ says
L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier applies
to a long double argument.
I'm thinking that support for "%Ld" might be a glibc accident. So..
* bfd.c (_doprnt): Replace "L" with "ll" when printing bfd_vma
as long long. Move code replacing "ll" with "I64", and simplify.
diff --git a/bfd/bfd.c b/bfd/bfd.c
index a119ac4..665f182 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -725,11 +725,17 @@ _doprnt (FILE *stream, const char *format, va_list ap)
{
/* L modifier for bfd_vma or bfd_size_type may be
either long long or long. */
- if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
- && sptr[-2] == 'L')
+ if (sptr[-2] == 'L')
{
- wide_width = 1;
sptr[-2] = 'l';
+ if (BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
+ wide_width = 1;
+ else
+ {
+ sptr[-1] = 'l';
+ *sptr++ = ptr[-1];
+ *sptr = '\0';
+ }
}
switch (wide_width)
@@ -742,17 +748,14 @@ _doprnt (FILE *stream, const char *format, va_list ap)
break;
case 2:
default:
-#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
-# if defined (__MSVCRT__)
- sptr--;
- while (sptr[-1] == 'L' || sptr[-1] == 'l')
- sptr--;
- *sptr++ = 'I';
- *sptr++ = '6';
- *sptr++ = '4';
+#if defined (__MSVCRT__)
+ sptr[-3] = 'I';
+ sptr[-2] = '6';
+ sptr[-1] = '4';
*sptr++ = ptr[-1];
*sptr = '\0';
-# endif
+#endif
+#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
PRINT_TYPE (long long);
#else
/* Fake it and hope for the best. */
--
Alan Modra
Australia Development Lab, IBM