From 49d3be771d5db26383bf7fa90ea6f83bbe9f2781 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Tue, 19 Aug 2025 05:35:01 +0100 Subject: [PATCH] Use defined stdint.h --- Makefile.unix | 4 ---- Makefile.w32 | 2 +- ranlib.c | 21 +++++++++++++++------ stdint.h | 8 ++++++++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Makefile.unix b/Makefile.unix index 02c268c..09ff4fc 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -7,10 +7,6 @@ VPATH := $(SRCDIR) CC := gcc CFLAGS := -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90 -ifneq ($(shell uname -s),Darwin) -CFLAGS += -m32 -endif - CSRC := append.c ar.c conv.c delete.c display.c extract.c lib.c ranlib.c replace.c report.c ifeq ($(OS), Windows_NT) diff --git a/Makefile.w32 b/Makefile.w32 index 9a70e98..7749f25 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -5,7 +5,7 @@ SRCDIR ?= $(CURDIR) VPATH := $(SRCDIR) CC := gcc -CFLAGS := -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -m32 -pedantic -std=c90 +CFLAGS := -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90 CSRC := append.c ar.c conv.c delete.c display.c extract.c lib.c ranlib.c replace.c report.c diff --git a/ranlib.c b/ranlib.c index 3c5227d..a34cefb 100644 --- a/ranlib.c +++ b/ranlib.c @@ -1,7 +1,6 @@ /****************************************************************************** * @file ranlib.c *****************************************************************************/ -#include #include #include #include @@ -312,8 +311,8 @@ static void coff_get_symbols (void *object, long offset) { : ((uint32_t) arr[0] | (((uint32_t) arr[1]) << 8) | (((uint32_t) arr[2]) << 16) | (((uint32_t) arr[3]) << 24))) #define GET_ELF_UINT64(arr) \ - (endianess ? (((uint_fast64_t) arr[0]) << 56) | (((uint_fast64_t) arr[1]) << 48) | (((uint_fast64_t) arr[2]) << 40) | (((uint_fast64_t) arr[3]) >> 32) | (((uint_fast64_t) arr[4]) << 24) | (((uint_fast64_t) arr[5]) << 16) | (((uint_fast64_t) arr[6]) << 8) | (((uint_fast64_t) arr[7])) \ - : ((uint_fast64_t) arr[0]) | (((uint_fast64_t) arr[1]) << 8) | (((uint_fast64_t) arr[2]) << 16) | (((uint_fast64_t) arr[3]) << 24) | (((uint_fast64_t) arr[4]) << 32) | (((uint_fast64_t) arr[5]) << 40) | (((uint_fast64_t) arr[6]) << 48) | (((uint_fast64_t) arr[7]) << 56)) + (endianess ? (((uint64_t) arr[0]) << 56) | (((uint64_t) arr[1]) << 48) | (((uint64_t) arr[2]) << 40) | (((uint64_t) arr[3]) >> 32) | (((uint64_t) arr[4]) << 24) | (((uint64_t) arr[5]) << 16) | (((uint64_t) arr[6]) << 8) | (((uint64_t) arr[7])) \ + : ((uint64_t) arr[0]) | (((uint64_t) arr[1]) << 8) | (((uint64_t) arr[2]) << 16) | (((uint64_t) arr[3]) << 24) | (((uint64_t) arr[4]) << 32) | (((uint64_t) arr[5]) << 40) | (((uint64_t) arr[6]) << 48) | (((uint64_t) arr[7]) << 56)) static void elf32_get_symbols (void *object, long offset, int endianess) { @@ -732,15 +731,21 @@ static void omf_get_symbols (void *object, char *filename, unsigned long bytes, void ranlib (void) { FILE *tfp = tmpfile (); - long offset = 0; struct ar_header header; - long bytes, i, j, len, read, val; + long i, j, len, read, val; unsigned char *object; void *contents; char temp[16]; + long offset = 0; + +#if UINT_MAX == 65535 + long bytes; +#else + int bytes; +#endif for (;;) { @@ -910,9 +915,13 @@ void ranlib (void) { memcpy (header.group, temp, 6); memcpy (header.mode, temp, 8); +#if UINT_MAX == 65535 len = sprintf (temp, "%ld", bytes + 4); - temp[len] = ' '; +#else + len = sprintf (temp, "%d", bytes + 4); +#endif + temp[len] = ' '; memcpy (header.size, temp, 10); header.endsig[0] = '`'; diff --git a/stdint.h b/stdint.h index f4b18c0..5163ae3 100644 --- a/stdint.h +++ b/stdint.h @@ -20,4 +20,12 @@ typedef signed int int32_t; typedef unsigned int uint32_t; #endif +#if ULONG_MAX == 4294967295 && !defined (NO_LONG_LONG) +typedef signed long long int64_t; +typedef signed long long uint64_t; +#else +typedef signed long int64_t; +typedef unsigned long uint64_t; +#endif + #endif /* _STDINT_H */ -- 2.34.1