From 27654dcbfea3fbbda292535b1704b0f40400d6ec Mon Sep 17 00:00:00 2001 From: Philip Guenther Date: Sun, 10 May 2015 20:41:20 +0000 Subject: Add _bfd_ar_spacepadll() for formatting long long values in archive headers. ok kettenis@ --- gnu/usr.bin/binutils-2.17/bfd/archive.c | 28 ++++++++++++++++++++++------ gnu/usr.bin/binutils-2.17/bfd/archive64.c | 2 +- gnu/usr.bin/binutils-2.17/bfd/libbfd-in.h | 2 ++ gnu/usr.bin/binutils-2.17/bfd/libbfd.h | 2 ++ gnu/usr.bin/binutils-2.17/bfd/som.c | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gnu/usr.bin/binutils-2.17/bfd/archive.c b/gnu/usr.bin/binutils-2.17/bfd/archive.c index 38c24840cfc..cb8b0c1d9f1 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/archive.c +++ b/gnu/usr.bin/binutils-2.17/bfd/archive.c @@ -175,6 +175,22 @@ _bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val) memcpy (p, buf, n); } +void +_bfd_ar_spacepadll (char *p, size_t n, const char *fmt, long long val) +{ + static char buf[20]; + size_t len; + snprintf (buf, sizeof (buf), fmt, val); + len = strlen (buf); + if (len < n) + { + memcpy (p, buf, len); + memset (p + len, ' ', n - len); + } + else + memcpy (p, buf, n); +} + bfd_boolean _bfd_generic_mkarchive (bfd *abfd) { @@ -1390,8 +1406,8 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member) /* ar headers are space padded, not null padded! */ memset (hdr, ' ', sizeof (struct ar_hdr)); - _bfd_ar_spacepad (hdr->ar_date, sizeof (hdr->ar_date), "%-12lld", - (long long)status.st_mtime); + _bfd_ar_spacepadll (hdr->ar_date, sizeof (hdr->ar_date), "%-12lld", + status.st_mtime); #ifdef HPUX_LARGE_AR_IDS /* HP has a very "special" way to handle UID/GID's with numeric values > 99999. */ @@ -1412,7 +1428,7 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member) status.st_gid); _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo", status.st_mode); - _bfd_ar_spacepad (hdr->ar_size, sizeof (hdr->ar_size), "%-10ld", + _bfd_ar_spacepadll (hdr->ar_size, sizeof (hdr->ar_size), "%-10lld", status.st_size); memcpy (hdr->ar_fmag, ARFMAG, 2); ared->parsed_size = status.st_size; @@ -1945,7 +1961,7 @@ bsd_write_armap (bfd *arch, bfd_ardata (arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET; bfd_ardata (arch)->armap_datepos = (SARMAG + offsetof (struct ar_hdr, ar_date[0])); - _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", + _bfd_ar_spacepadll (hdr.ar_date, sizeof (hdr.ar_date), "%lld", bfd_ardata (arch)->armap_timestamp); _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", getuid ()); _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", getgid ()); @@ -2035,7 +2051,7 @@ _bfd_archive_bsd_update_armap_timestamp (bfd *arch) /* Prepare an ASCII version suitable for writing. */ memset (hdr.ar_date, ' ', sizeof (hdr.ar_date)); - _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", + _bfd_ar_spacepadll (hdr.ar_date, sizeof (hdr.ar_date), "%lld", bfd_ardata (arch)->armap_timestamp); /* Write it into the file. */ @@ -2099,7 +2115,7 @@ coff_write_armap (bfd *arch, hdr.ar_name[0] = '/'; _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", mapsize); - _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", + _bfd_ar_spacepadll (hdr.ar_date, sizeof (hdr.ar_date), "%lld", time (NULL)); /* This, at least, is what Intel coff sets the values to. */ _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0); diff --git a/gnu/usr.bin/binutils-2.17/bfd/archive64.c b/gnu/usr.bin/binutils-2.17/bfd/archive64.c index 3b28f853c21..98021772241 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/archive64.c +++ b/gnu/usr.bin/binutils-2.17/bfd/archive64.c @@ -172,7 +172,7 @@ bfd_elf64_archive_write_armap (bfd *arch, memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/")); _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", mapsize); - _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", + _bfd_ar_spacepadll (hdr.ar_date, sizeof (hdr.ar_date), "%lld", time (NULL)); /* This, at least, is what Intel coff sets the values to.: */ _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0); diff --git a/gnu/usr.bin/binutils-2.17/bfd/libbfd-in.h b/gnu/usr.bin/binutils-2.17/bfd/libbfd-in.h index 82f7d68042a..3a7e81a7b7f 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/libbfd-in.h +++ b/gnu/usr.bin/binutils-2.17/bfd/libbfd-in.h @@ -196,6 +196,8 @@ extern void *_bfd_generic_read_ar_hdr (bfd *); extern void _bfd_ar_spacepad (char *, size_t, const char *, long); +extern void _bfd_ar_spacepadll + (char *, size_t, const char *, long long); extern void *_bfd_generic_read_ar_hdr_mag (bfd *, const char *); diff --git a/gnu/usr.bin/binutils-2.17/bfd/libbfd.h b/gnu/usr.bin/binutils-2.17/bfd/libbfd.h index ff1bb0bbaaa..eccb42b047a 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/libbfd.h +++ b/gnu/usr.bin/binutils-2.17/bfd/libbfd.h @@ -201,6 +201,8 @@ extern void *_bfd_generic_read_ar_hdr (bfd *); extern void _bfd_ar_spacepad (char *, size_t, const char *, long); +extern void _bfd_ar_spacepadll + (char *, size_t, const char *, long long); extern void *_bfd_generic_read_ar_hdr_mag (bfd *, const char *); diff --git a/gnu/usr.bin/binutils-2.17/bfd/som.c b/gnu/usr.bin/binutils-2.17/bfd/som.c index 0c9e1b79f9c..ea8b973d207 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/som.c +++ b/gnu/usr.bin/binutils-2.17/bfd/som.c @@ -6166,7 +6166,7 @@ som_write_armap (bfd *abfd, lst.checksum ^= *p++; sprintf (hdr.ar_name, "/ "); - sprintf (hdr.ar_date, "%ld", bfd_ardata (abfd)->armap_timestamp); + sprintf (hdr.ar_date, "%lld", (long long)bfd_ardata (abfd)->armap_timestamp); sprintf (hdr.ar_uid, "%ld", (long) getuid ()); sprintf (hdr.ar_gid, "%ld", (long) getgid ()); sprintf (hdr.ar_mode, "%-8o", (unsigned int) statbuf.st_mode); -- cgit v1.2.3