1 /* Copyright (C) 2006-2022 Free Software Foundation, Inc.
2 Written by Paul Eggert, Bruno Haible, Derek Price.
3 This file is part of gnulib.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 * ISO C 99 <inttypes.h> for platforms that lack it.
20 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html>
24 @PRAGMA_SYSTEM_HEADER@
28 /* Include the original <inttypes.h> if it exists, and if this file
29 has not been included yet or if this file includes gnulib stdint.h
30 which in turn includes this file.
31 The include_next requires a split double-inclusion guard. */
32 #if ! defined INTTYPES_H || defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
33 # if @HAVE_INTTYPES_H@
35 /* Some pre-C++11 <stdint.h> implementations need this. */
36 # if defined __cplusplus && ! defined __STDC_FORMAT_MACROS
37 # define __STDC_FORMAT_MACROS 1
40 # @INCLUDE_NEXT@ @NEXT_INTTYPES_H@
42 # define _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H
46 #if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
49 /* Include <stdint.h> or the gnulib replacement.
50 But avoid namespace pollution on glibc systems. */
54 /* Get CHAR_BIT, INT_MAX, LONG_MAX, etc. */
56 /* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */
57 #if defined _WIN32 && ! defined __CYGWIN__
61 #if !(INT_MAX == 0x7fffffff && INT_MIN + INT_MAX == -1)
62 # error "This file assumes that 'int' is 32-bit two's complement. Please report your platform and compiler to <bug-gnulib@gnu.org>."
65 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
67 /* The definition of _GL_ARG_NONNULL is copied here. */
69 /* The definition of _GL_WARN_ON_USE is copied here. */
71 /* 7.8.1 Macros for format specifiers */
73 #if defined _TNS_R_TARGET
74 /* Tandem NonStop R series and compatible platforms released before
75 July 2005 support %Ld but not %lld. */
76 # define _LONG_LONG_FORMAT_PREFIX "L"
78 # define _LONG_LONG_FORMAT_PREFIX "ll"
172 # if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
173 # define _PRI64_PREFIX "l"
174 # elif defined _MSC_VER || defined __MINGW32__
175 # define _PRI64_PREFIX "I64"
176 # elif LONG_MAX >> 30 == 1
177 # define _PRI64_PREFIX _LONG_LONG_FORMAT_PREFIX
180 # define PRId64 _PRI64_PREFIX "d"
183 # define PRIi64 _PRI64_PREFIX "i"
187 # if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
188 # define _PRIu64_PREFIX "l"
189 # elif defined _MSC_VER || defined __MINGW32__
190 # define _PRIu64_PREFIX "I64"
191 # elif ULONG_MAX >> 31 == 1
192 # define _PRIu64_PREFIX _LONG_LONG_FORMAT_PREFIX
195 # define PRIo64 _PRIu64_PREFIX "o"
198 # define PRIu64 _PRIu64_PREFIX "u"
201 # define PRIx64 _PRIu64_PREFIX "x"
204 # define PRIX64 _PRIu64_PREFIX "X"
208 #if !defined PRIdLEAST8
209 # define PRIdLEAST8 "d"
211 #if !defined PRIiLEAST8
212 # define PRIiLEAST8 "i"
214 #if !defined PRIoLEAST8
215 # define PRIoLEAST8 "o"
217 #if !defined PRIuLEAST8
218 # define PRIuLEAST8 "u"
220 #if !defined PRIxLEAST8
221 # define PRIxLEAST8 "x"
223 #if !defined PRIXLEAST8
224 # define PRIXLEAST8 "X"
226 #if !defined PRIdLEAST16
227 # define PRIdLEAST16 "d"
229 #if !defined PRIiLEAST16
230 # define PRIiLEAST16 "i"
232 #if !defined PRIoLEAST16
233 # define PRIoLEAST16 "o"
235 #if !defined PRIuLEAST16
236 # define PRIuLEAST16 "u"
238 #if !defined PRIxLEAST16
239 # define PRIxLEAST16 "x"
241 #if !defined PRIXLEAST16
242 # define PRIXLEAST16 "X"
244 #if !defined PRIdLEAST32
245 # define PRIdLEAST32 "d"
247 #if !defined PRIiLEAST32
248 # define PRIiLEAST32 "i"
250 #if !defined PRIoLEAST32
251 # define PRIoLEAST32 "o"
253 #if !defined PRIuLEAST32
254 # define PRIuLEAST32 "u"
256 #if !defined PRIxLEAST32
257 # define PRIxLEAST32 "x"
259 #if !defined PRIXLEAST32
260 # define PRIXLEAST32 "X"
263 # if !defined PRIdLEAST64
264 # define PRIdLEAST64 PRId64
266 # if !defined PRIiLEAST64
267 # define PRIiLEAST64 PRIi64
271 # if !defined PRIoLEAST64
272 # define PRIoLEAST64 PRIo64
274 # if !defined PRIuLEAST64
275 # define PRIuLEAST64 PRIu64
277 # if !defined PRIxLEAST64
278 # define PRIxLEAST64 PRIx64
280 # if !defined PRIXLEAST64
281 # define PRIXLEAST64 PRIX64
285 #if !defined PRIdFAST8
286 # if INT_FAST8_MAX > INT32_MAX
287 # define PRIdFAST8 PRId64
289 # define PRIdFAST8 "d"
292 #if !defined PRIiFAST8
293 # if INT_FAST8_MAX > INT32_MAX
294 # define PRIiFAST8 PRIi64
296 # define PRIiFAST8 "i"
299 #if !defined PRIoFAST8
300 # if UINT_FAST8_MAX > UINT32_MAX
301 # define PRIoFAST8 PRIo64
303 # define PRIoFAST8 "o"
306 #if !defined PRIuFAST8
307 # if UINT_FAST8_MAX > UINT32_MAX
308 # define PRIuFAST8 PRIu64
310 # define PRIuFAST8 "u"
313 #if !defined PRIxFAST8
314 # if UINT_FAST8_MAX > UINT32_MAX
315 # define PRIxFAST8 PRIx64
317 # define PRIxFAST8 "x"
320 #if !defined PRIXFAST8
321 # if UINT_FAST8_MAX > UINT32_MAX
322 # define PRIXFAST8 PRIX64
324 # define PRIXFAST8 "X"
327 #if !defined PRIdFAST16
328 # if INT_FAST16_MAX > INT32_MAX
329 # define PRIdFAST16 PRId64
331 # define PRIdFAST16 "d"
334 #if !defined PRIiFAST16
335 # if INT_FAST16_MAX > INT32_MAX
336 # define PRIiFAST16 PRIi64
338 # define PRIiFAST16 "i"
341 #if !defined PRIoFAST16
342 # if UINT_FAST16_MAX > UINT32_MAX
343 # define PRIoFAST16 PRIo64
345 # define PRIoFAST16 "o"
348 #if !defined PRIuFAST16
349 # if UINT_FAST16_MAX > UINT32_MAX
350 # define PRIuFAST16 PRIu64
352 # define PRIuFAST16 "u"
355 #if !defined PRIxFAST16
356 # if UINT_FAST16_MAX > UINT32_MAX
357 # define PRIxFAST16 PRIx64
359 # define PRIxFAST16 "x"
362 #if !defined PRIXFAST16
363 # if UINT_FAST16_MAX > UINT32_MAX
364 # define PRIXFAST16 PRIX64
366 # define PRIXFAST16 "X"
369 #if !defined PRIdFAST32
370 # if INT_FAST32_MAX > INT32_MAX
371 # define PRIdFAST32 PRId64
373 # define PRIdFAST32 "d"
376 #if !defined PRIiFAST32
377 # if INT_FAST32_MAX > INT32_MAX
378 # define PRIiFAST32 PRIi64
380 # define PRIiFAST32 "i"
383 #if !defined PRIoFAST32
384 # if UINT_FAST32_MAX > UINT32_MAX
385 # define PRIoFAST32 PRIo64
387 # define PRIoFAST32 "o"
390 #if !defined PRIuFAST32
391 # if UINT_FAST32_MAX > UINT32_MAX
392 # define PRIuFAST32 PRIu64
394 # define PRIuFAST32 "u"
397 #if !defined PRIxFAST32
398 # if UINT_FAST32_MAX > UINT32_MAX
399 # define PRIxFAST32 PRIx64
401 # define PRIxFAST32 "x"
404 #if !defined PRIXFAST32
405 # if UINT_FAST32_MAX > UINT32_MAX
406 # define PRIXFAST32 PRIX64
408 # define PRIXFAST32 "X"
412 # if !defined PRIdFAST64
413 # define PRIdFAST64 PRId64
415 # if !defined PRIiFAST64
416 # define PRIiFAST64 PRIi64
420 # if !defined PRIoFAST64
421 # define PRIoFAST64 PRIo64
423 # if !defined PRIuFAST64
424 # define PRIuFAST64 PRIu64
426 # if !defined PRIxFAST64
427 # define PRIxFAST64 PRIx64
429 # if !defined PRIXFAST64
430 # define PRIXFAST64 PRIX64
435 # if @INT32_MAX_LT_INTMAX_MAX@
436 # define PRIdMAX PRId64
438 # define PRIdMAX "ld"
442 # if @INT32_MAX_LT_INTMAX_MAX@
443 # define PRIiMAX PRIi64
445 # define PRIiMAX "li"
449 # if @UINT32_MAX_LT_UINTMAX_MAX@
450 # define PRIoMAX PRIo64
452 # define PRIoMAX "lo"
456 # if @UINT32_MAX_LT_UINTMAX_MAX@
457 # define PRIuMAX PRIu64
459 # define PRIuMAX "lu"
463 # if @UINT32_MAX_LT_UINTMAX_MAX@
464 # define PRIxMAX PRIx64
466 # define PRIxMAX "lx"
470 # if @UINT32_MAX_LT_UINTMAX_MAX@
471 # define PRIXMAX PRIX64
473 # define PRIXMAX "lX"
479 # define PRIdPTR @PRIPTR_PREFIX@ "d"
484 # define PRIiPTR @PRIPTR_PREFIX@ "i"
489 # define PRIoPTR @PRIPTR_PREFIX@ "o"
494 # define PRIuPTR @PRIPTR_PREFIX@ "u"
499 # define PRIxPTR @PRIPTR_PREFIX@ "x"
504 # define PRIXPTR @PRIPTR_PREFIX@ "X"
584 # if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @INT64_MAX_EQ_LONG_MAX@)
585 # define _SCN64_PREFIX "l"
586 # elif defined _MSC_VER || defined __MINGW32__
587 # define _SCN64_PREFIX "I64"
588 # elif LONG_MAX >> 30 == 1
589 # define _SCN64_PREFIX _LONG_LONG_FORMAT_PREFIX
592 # define SCNd64 _SCN64_PREFIX "d"
595 # define SCNi64 _SCN64_PREFIX "i"
599 # if (@APPLE_UNIVERSAL_BUILD@ ? defined _LP64 : @UINT64_MAX_EQ_ULONG_MAX@)
600 # define _SCNu64_PREFIX "l"
601 # elif defined _MSC_VER || defined __MINGW32__
602 # define _SCNu64_PREFIX "I64"
603 # elif ULONG_MAX >> 31 == 1
604 # define _SCNu64_PREFIX _LONG_LONG_FORMAT_PREFIX
607 # define SCNo64 _SCNu64_PREFIX "o"
610 # define SCNu64 _SCNu64_PREFIX "u"
613 # define SCNx64 _SCNu64_PREFIX "x"
617 #if !defined SCNdLEAST8
618 # define SCNdLEAST8 "hhd"
620 #if !defined SCNiLEAST8
621 # define SCNiLEAST8 "hhi"
623 #if !defined SCNoLEAST8
624 # define SCNoLEAST8 "hho"
626 #if !defined SCNuLEAST8
627 # define SCNuLEAST8 "hhu"
629 #if !defined SCNxLEAST8
630 # define SCNxLEAST8 "hhx"
632 #if !defined SCNdLEAST16
633 # define SCNdLEAST16 "hd"
635 #if !defined SCNiLEAST16
636 # define SCNiLEAST16 "hi"
638 #if !defined SCNoLEAST16
639 # define SCNoLEAST16 "ho"
641 #if !defined SCNuLEAST16
642 # define SCNuLEAST16 "hu"
644 #if !defined SCNxLEAST16
645 # define SCNxLEAST16 "hx"
647 #if !defined SCNdLEAST32
648 # define SCNdLEAST32 "d"
650 #if !defined SCNiLEAST32
651 # define SCNiLEAST32 "i"
653 #if !defined SCNoLEAST32
654 # define SCNoLEAST32 "o"
656 #if !defined SCNuLEAST32
657 # define SCNuLEAST32 "u"
659 #if !defined SCNxLEAST32
660 # define SCNxLEAST32 "x"
663 # if !defined SCNdLEAST64
664 # define SCNdLEAST64 SCNd64
666 # if !defined SCNiLEAST64
667 # define SCNiLEAST64 SCNi64
671 # if !defined SCNoLEAST64
672 # define SCNoLEAST64 SCNo64
674 # if !defined SCNuLEAST64
675 # define SCNuLEAST64 SCNu64
677 # if !defined SCNxLEAST64
678 # define SCNxLEAST64 SCNx64
682 #if !defined SCNdFAST8
683 # if INT_FAST8_MAX > INT32_MAX
684 # define SCNdFAST8 SCNd64
685 # elif INT_FAST8_MAX == 0x7fff
686 # define SCNdFAST8 "hd"
687 # elif INT_FAST8_MAX == 0x7f
688 # define SCNdFAST8 "hhd"
690 # define SCNdFAST8 "d"
693 #if !defined SCNiFAST8
694 # if INT_FAST8_MAX > INT32_MAX
695 # define SCNiFAST8 SCNi64
696 # elif INT_FAST8_MAX == 0x7fff
697 # define SCNiFAST8 "hi"
698 # elif INT_FAST8_MAX == 0x7f
699 # define SCNiFAST8 "hhi"
701 # define SCNiFAST8 "i"
704 #if !defined SCNoFAST8
705 # if UINT_FAST8_MAX > UINT32_MAX
706 # define SCNoFAST8 SCNo64
707 # elif UINT_FAST8_MAX == 0xffff
708 # define SCNoFAST8 "ho"
709 # elif UINT_FAST8_MAX == 0xff
710 # define SCNoFAST8 "hho"
712 # define SCNoFAST8 "o"
715 #if !defined SCNuFAST8
716 # if UINT_FAST8_MAX > UINT32_MAX
717 # define SCNuFAST8 SCNu64
718 # elif UINT_FAST8_MAX == 0xffff
719 # define SCNuFAST8 "hu"
720 # elif UINT_FAST8_MAX == 0xff
721 # define SCNuFAST8 "hhu"
723 # define SCNuFAST8 "u"
726 #if !defined SCNxFAST8
727 # if UINT_FAST8_MAX > UINT32_MAX
728 # define SCNxFAST8 SCNx64
729 # elif UINT_FAST8_MAX == 0xffff
730 # define SCNxFAST8 "hx"
731 # elif UINT_FAST8_MAX == 0xff
732 # define SCNxFAST8 "hhx"
734 # define SCNxFAST8 "x"
737 #if !defined SCNdFAST16
738 # if INT_FAST16_MAX > INT32_MAX
739 # define SCNdFAST16 SCNd64
740 # elif INT_FAST16_MAX == 0x7fff
741 # define SCNdFAST16 "hd"
743 # define SCNdFAST16 "d"
746 #if !defined SCNiFAST16
747 # if INT_FAST16_MAX > INT32_MAX
748 # define SCNiFAST16 SCNi64
749 # elif INT_FAST16_MAX == 0x7fff
750 # define SCNiFAST16 "hi"
752 # define SCNiFAST16 "i"
755 #if !defined SCNoFAST16
756 # if UINT_FAST16_MAX > UINT32_MAX
757 # define SCNoFAST16 SCNo64
758 # elif UINT_FAST16_MAX == 0xffff
759 # define SCNoFAST16 "ho"
761 # define SCNoFAST16 "o"
764 #if !defined SCNuFAST16
765 # if UINT_FAST16_MAX > UINT32_MAX
766 # define SCNuFAST16 SCNu64
767 # elif UINT_FAST16_MAX == 0xffff
768 # define SCNuFAST16 "hu"
770 # define SCNuFAST16 "u"
773 #if !defined SCNxFAST16
774 # if UINT_FAST16_MAX > UINT32_MAX
775 # define SCNxFAST16 SCNx64
776 # elif UINT_FAST16_MAX == 0xffff
777 # define SCNxFAST16 "hx"
779 # define SCNxFAST16 "x"
782 #if !defined SCNdFAST32
783 # if INT_FAST32_MAX > INT32_MAX
784 # define SCNdFAST32 SCNd64
786 # define SCNdFAST32 "d"
789 #if !defined SCNiFAST32
790 # if INT_FAST32_MAX > INT32_MAX
791 # define SCNiFAST32 SCNi64
793 # define SCNiFAST32 "i"
796 #if !defined SCNoFAST32
797 # if UINT_FAST32_MAX > UINT32_MAX
798 # define SCNoFAST32 SCNo64
800 # define SCNoFAST32 "o"
803 #if !defined SCNuFAST32
804 # if UINT_FAST32_MAX > UINT32_MAX
805 # define SCNuFAST32 SCNu64
807 # define SCNuFAST32 "u"
810 #if !defined SCNxFAST32
811 # if UINT_FAST32_MAX > UINT32_MAX
812 # define SCNxFAST32 SCNx64
814 # define SCNxFAST32 "x"
818 # if !defined SCNdFAST64
819 # define SCNdFAST64 SCNd64
821 # if !defined SCNiFAST64
822 # define SCNiFAST64 SCNi64
826 # if !defined SCNoFAST64
827 # define SCNoFAST64 SCNo64
829 # if !defined SCNuFAST64
830 # define SCNuFAST64 SCNu64
832 # if !defined SCNxFAST64
833 # define SCNxFAST64 SCNx64
838 # if @INT32_MAX_LT_INTMAX_MAX@
839 # define SCNdMAX SCNd64
841 # define SCNdMAX "ld"
845 # if @INT32_MAX_LT_INTMAX_MAX@
846 # define SCNiMAX SCNi64
848 # define SCNiMAX "li"
852 # if @UINT32_MAX_LT_UINTMAX_MAX@
853 # define SCNoMAX SCNo64
855 # define SCNoMAX "lo"
859 # if @UINT32_MAX_LT_UINTMAX_MAX@
860 # define SCNuMAX SCNu64
862 # define SCNuMAX "lu"
866 # if @UINT32_MAX_LT_UINTMAX_MAX@
867 # define SCNxMAX SCNx64
869 # define SCNxMAX "lx"
875 # define SCNdPTR @PRIPTR_PREFIX@ "d"
880 # define SCNiPTR @PRIPTR_PREFIX@ "i"
885 # define SCNoPTR @PRIPTR_PREFIX@ "o"
890 # define SCNuPTR @PRIPTR_PREFIX@ "u"
895 # define SCNxPTR @PRIPTR_PREFIX@ "x"
899 /* 7.8.2 Functions for greatest-width integer types */
906 # if !@HAVE_DECL_IMAXABS@
907 extern intmax_t imaxabs (intmax_t);
909 #elif defined GNULIB_POSIXCHECK
911 # if HAVE_RAW_DECL_IMAXABS
912 _GL_WARN_ON_USE (imaxabs
, "imaxabs is unportable - "
913 "use gnulib module imaxabs for portability");
918 # if !@HAVE_IMAXDIV_T@
919 # if !GNULIB_defined_imaxdiv_t
920 typedef struct { intmax_t quot
; intmax_t rem
; } imaxdiv_t
;
921 # define GNULIB_defined_imaxdiv_t 1
924 # if !@HAVE_DECL_IMAXDIV@
925 extern imaxdiv_t
imaxdiv (intmax_t, intmax_t);
927 #elif defined GNULIB_POSIXCHECK
929 # if HAVE_RAW_DECL_IMAXDIV
930 _GL_WARN_ON_USE (imaxdiv
, "imaxdiv is unportable - "
931 "use gnulib module imaxdiv for portability");
935 #if @GNULIB_STRTOIMAX@
936 # if @REPLACE_STRTOIMAX@
937 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
939 # define strtoimax rpl_strtoimax
941 _GL_FUNCDECL_RPL (strtoimax
, intmax_t,
942 (const char *restrict
, char **restrict
, int)
943 _GL_ARG_NONNULL ((1)));
944 _GL_CXXALIAS_RPL (strtoimax
, intmax_t,
945 (const char *restrict
, char **restrict
, int));
947 # if !@HAVE_DECL_STRTOIMAX@
949 _GL_FUNCDECL_SYS (strtoimax
, intmax_t,
950 (const char *restrict
, char **restrict
, int)
951 _GL_ARG_NONNULL ((1)));
953 _GL_CXXALIAS_SYS (strtoimax
, intmax_t,
954 (const char *restrict
, char **restrict
, int));
956 _GL_CXXALIASWARN (strtoimax
);
957 #elif defined GNULIB_POSIXCHECK
959 # if HAVE_RAW_DECL_STRTOIMAX
960 _GL_WARN_ON_USE (strtoimax
, "strtoimax is unportable - "
961 "use gnulib module strtoimax for portability");
965 #if @GNULIB_STRTOUMAX@
966 # if @REPLACE_STRTOUMAX@
967 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
969 # define strtoumax rpl_strtoumax
971 _GL_FUNCDECL_RPL (strtoumax
, uintmax_t,
972 (const char *restrict
, char **restrict
, int)
973 _GL_ARG_NONNULL ((1)));
974 _GL_CXXALIAS_RPL (strtoumax
, uintmax_t,
975 (const char *restrict
, char **restrict
, int));
977 # if !@HAVE_DECL_STRTOUMAX@
979 _GL_FUNCDECL_SYS (strtoumax
, uintmax_t,
980 (const char *restrict
, char **restrict
, int)
981 _GL_ARG_NONNULL ((1)));
983 _GL_CXXALIAS_SYS (strtoumax
, uintmax_t,
984 (const char *restrict
, char **restrict
, int));
986 _GL_CXXALIASWARN (strtoumax
);
987 #elif defined GNULIB_POSIXCHECK
989 # if HAVE_RAW_DECL_STRTOUMAX
990 _GL_WARN_ON_USE (strtoumax
, "strtoumax is unportable - "
991 "use gnulib module strtoumax for portability");
995 /* Don't bother defining or declaring wcstoimax and wcstoumax, since
996 wide-character functions like this are hardly ever useful. */
1002 #endif /* !defined INTTYPES_H && !defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H */