From 92c1a9624e9e4f9c1288d6bcd4c66a7c414638e8 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Tue, 1 Jul 2025 11:28:29 +0800
Subject: [PATCH] Define __STDC_FORMAT_MACROS for PRIu64 and friends

---
 crypto/asn1/a_strex.cc                    | 4 ++++
 crypto/bytestring/cbs.cc                  | 4 ++++
 crypto/err/err.cc                         | 4 ++++
 crypto/rand/fork_detect_test.cc           | 5 +++++
 include/openssl/bn.h                      | 4 ++++
 ssl/test/packeted_bio.cc                  | 4 ++++
 tool/speed.cc                             | 4 ++++
 util/fipstools/acvp/modulewrapper/main.cc | 4 ++++
 8 files changed, 33 insertions(+)

diff --git crypto/asn1/a_strex.cc crypto/asn1/a_strex.cc
index a2d5e2cb7..52d881098 100644
--- a/crypto/asn1/a_strex.cc
+++ b/crypto/asn1/a_strex.cc
@@ -14,6 +14,10 @@
 
 #include <openssl/asn1.h>
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <assert.h>
 #include <ctype.h>
 #include <inttypes.h>
diff --git crypto/bytestring/cbs.cc crypto/bytestring/cbs.cc
index fd11c5a89..fb3f3c55b 100644
--- a/crypto/bytestring/cbs.cc
+++ b/crypto/bytestring/cbs.cc
@@ -16,6 +16,10 @@
 #include <openssl/bytestring.h>
 #include <openssl/mem.h>
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <assert.h>
 #include <ctype.h>
 #include <inttypes.h>
diff --git crypto/err/err.cc crypto/err/err.cc
index 64caf27cf..ff0391358 100644
--- a/crypto/err/err.cc
+++ b/crypto/err/err.cc
@@ -16,6 +16,10 @@
 #define _BORINGSSL_PROHIBIT_OPENSSL_MALLOC
 #include <openssl/err.h>
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
diff --git crypto/rand/fork_detect_test.cc crypto/rand/fork_detect_test.cc
index 5bc7829cb..b01864bfd 100644
--- a/crypto/rand/fork_detect_test.cc
+++ b/crypto/rand/fork_detect_test.cc
@ -22,6 +22,10 @@
 #if defined(OPENSSL_FORK_DETECTION) && !defined(OPENSSL_TSAN) && \
     !defined(OPENSSL_IOS)
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <errno.h>
 #include <inttypes.h>
 #include <stdio.h>
diff --git include/openssl/bn.h include/openssl/bn.h
index 82099753b..0092916e7 100644
--- a/include/openssl/bn.h
+++ b/include/openssl/bn.h
@@ -18,6 +18,10 @@
 
 #include <openssl/base.h>   // IWYU pragma: export
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <inttypes.h>  // for PRIu64 and friends
 #include <stdio.h>  // for FILE*
 
diff --git ssl/test/packeted_bio.cc ssl/test/packeted_bio.cc
index b30699bf6..8c9a758f1 100644
--- a/ssl/test/packeted_bio.cc
+++ b/ssl/test/packeted_bio.cc
@@ -14,6 +14,10 @@
 
 #include "packeted_bio.h"
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <assert.h>
 #include <inttypes.h>
 #include <limits.h>
diff --git util/fipstools/acvp/modulewrapper/main.cc util/fipstools/acvp/modulewrapper/main.cc
index 9a1118bf1..96f22b02c 100644
--- a/util/fipstools/acvp/modulewrapper/main.cc
+++ b/util/fipstools/acvp/modulewrapper/main.cc
@@ -12,6 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>

--- a/bench/main.cc	2026-02-11 22:55:20.000000000 +0800
+++ b/bench/main.cc	2026-02-14 07:43:17.000000000 +0800
@@ -12,6 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>

--- a/crypto/rand/fork_detect_test.cc	2026-05-08 19:25:09.000000000 +0800
+++ b/crypto/rand/fork_detect_test.cc	2026-05-15 10:05:30.000000000 +0800
@@ -22,6 +22,10 @@
 #if defined(OPENSSL_FORK_DETECTION) && !defined(OPENSSL_TSAN) && \
     !defined(OPENSSL_IOS)
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <errno.h>
 #include <inttypes.h>
 #include <stdio.h>

--- a/pki/verify_certificate_chain.cc	2026-06-16 20:32:16.000000000 +0800
+++ b/pki/verify_certificate_chain.cc	2026-07-09 22:55:04.000000000 +0800
@@ -14,6 +14,10 @@
 
 #include "verify_certificate_chain.h"
 
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <algorithm>
 #include <cassert>
 
