Skip to content

Commit

Permalink
include: replace stdint.h and inttypes.h with llvm's versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler569 committed May 9, 2024
1 parent f7ae33e commit 637fe6a
Show file tree
Hide file tree
Showing 2 changed files with 969 additions and 482 deletions.
142 changes: 97 additions & 45 deletions include/inttypes.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,97 @@
#pragma once

#include <stdint.h>

#define PRId8 "%hhd"
#define PRId16 "%hd"
#define PRId32 "%d"
#define PRId64 "%ld"
#define PRIdMAX "%zd"
#define PRIdPTR "%zd"

#define PRIi8 "%hhi"
#define PRIi16 "%hi"
#define PRIi32 "%i"
#define PRIi64 "%li"
#define PRIiMAX "%zi"
#define PRIiPTR "%zi"

#define PRIu8 "%hhu"
#define PRIu16 "%hu"
#define PRIu32 "%u"
#define PRIu64 "%lu"
#define PRIuMAX "%zu"
#define PRIuPTR "%zu"

#define PRIx8 "%hhx"
#define PRIx16 "%hx"
#define PRIx32 "%x"
#define PRIx64 "%lx"
#define PRIxMAX "%zx"
#define PRIxPTR "%zx"

#define PRIX8 "%hhX"
#define PRIX16 "%hX"
#define PRIX32 "%X"
#define PRIX64 "%lX"
#define PRIXMAX "%zX"
#define PRIXPTR "%zX"

#define PRIo8 "%hho"
#define PRIo16 "%ho"
#define PRIo32 "%o"
#define PRIo64 "%lo"
#define PRIoMAX "%zo"
#define PRIoPTR "%zo"
/*===---- inttypes.h - Standard header for integer printf macros ----------===*\
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
\*===----------------------------------------------------------------------===*/

#ifndef __CLANG_INTTYPES_H
// AIX system headers need inttypes.h to be re-enterable while _STD_TYPES_T
// is defined until an inclusion of it without _STD_TYPES_T occurs, in which
// case the header guard macro is defined.
#if !defined(_AIX) || !defined(_STD_TYPES_T)
#define __CLANG_INTTYPES_H
#endif

#if defined(_MSC_VER) && _MSC_VER < 1800
#error MSVC does not have inttypes.h prior to Visual Studio 2013
#endif

#include_next <inttypes.h>

#if defined(_MSC_VER) && _MSC_VER < 1900
/* MSVC headers define int32_t as int, but PRIx32 as "lx" instead of "x".
* This triggers format warnings, so fix it up here. */
#undef PRId32
#undef PRIdLEAST32
#undef PRIdFAST32
#undef PRIi32
#undef PRIiLEAST32
#undef PRIiFAST32
#undef PRIo32
#undef PRIoLEAST32
#undef PRIoFAST32
#undef PRIu32
#undef PRIuLEAST32
#undef PRIuFAST32
#undef PRIx32
#undef PRIxLEAST32
#undef PRIxFAST32
#undef PRIX32
#undef PRIXLEAST32
#undef PRIXFAST32

#undef SCNd32
#undef SCNdLEAST32
#undef SCNdFAST32
#undef SCNi32
#undef SCNiLEAST32
#undef SCNiFAST32
#undef SCNo32
#undef SCNoLEAST32
#undef SCNoFAST32
#undef SCNu32
#undef SCNuLEAST32
#undef SCNuFAST32
#undef SCNx32
#undef SCNxLEAST32
#undef SCNxFAST32

#define PRId32 "d"
#define PRIdLEAST32 "d"
#define PRIdFAST32 "d"
#define PRIi32 "i"
#define PRIiLEAST32 "i"
#define PRIiFAST32 "i"
#define PRIo32 "o"
#define PRIoLEAST32 "o"
#define PRIoFAST32 "o"
#define PRIu32 "u"
#define PRIuLEAST32 "u"
#define PRIuFAST32 "u"
#define PRIx32 "x"
#define PRIxLEAST32 "x"
#define PRIxFAST32 "x"
#define PRIX32 "X"
#define PRIXLEAST32 "X"
#define PRIXFAST32 "X"

#define SCNd32 "d"
#define SCNdLEAST32 "d"
#define SCNdFAST32 "d"
#define SCNi32 "i"
#define SCNiLEAST32 "i"
#define SCNiFAST32 "i"
#define SCNo32 "o"
#define SCNoLEAST32 "o"
#define SCNoFAST32 "o"
#define SCNu32 "u"
#define SCNuLEAST32 "u"
#define SCNuFAST32 "u"
#define SCNx32 "x"
#define SCNxLEAST32 "x"
#define SCNxFAST32 "x"
#endif

#endif /* __CLANG_INTTYPES_H */
Loading

0 comments on commit 637fe6a

Please sign in to comment.