]> git.draconx.ca Git - dxcommon.git/commitdiff
copysym: Avoid dependency on <stdint.h>
authorNick Bowler <nbowler@draconx.ca>
Fri, 17 Nov 2023 04:07:34 +0000 (23:07 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 18 Nov 2023 21:39:55 +0000 (16:39 -0500)
The <inttypes.h> header is older and a bit more portable.  But even
then, it is not really essential for this code.  So adjust things to
use <inttypes.h> only if the Autoconf-provided HAVE_INTTYPES_H is
defined; otherwise a C89 <limits.h>-based fallback is used.

src/copysym.c

index 3d72d6aad9f246eb6aa307669fafc289b2a91918..6ff93f35eb821a0f1af7c99a3aa6d1c455992cb9 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <stdint.h>
+
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+typedef uint_least32_t dx_u32;
+typedef uint_least64_t dx_u64;
+#else
+#include <limits.h>
+#if UINT_MAX >= 0xffffffff
+typedef unsigned dx_u32;
+#else
+typedef unsigned long dx_u32;
+#endif
+typedef unsigned long long dx_u64;
+#endif
 
 #define ARRAYSIZE(x) (sizeof (x) / sizeof (x)[0])
 
@@ -124,7 +137,7 @@ const char *copyright_symbol(const char *charset)
         * codes array for the corresponding index in t1, except that
         * ISO-8859 matches the special value '2' (handled below).
         */
-       uint_least64_t results = 0x001921fb13777511;
+       dx_u64 results = 0x001921fb13777511;
        const char (*m1)[sizeof *t1];
        unsigned x, cindex;
 
@@ -164,8 +177,8 @@ const char *copyright_symbol(const char *charset)
                 * two digits.  The set bits in the 'accept' value indicate
                 * which encodings have the copyright symbol.
                 */
-               uint_least32_t accept  = 0x00380383;
-               uint_least32_t collect = 0;
+               dx_u32 accept  = 0x00380383;
+               dx_u32 collect = 0;
                char c;
 
                while ((c = *charset++)) {