140 lines
3.2 KiB
Diff
140 lines
3.2 KiB
Diff
From 98e688a9da5e7b2925dda17a2d6820dddf1fb287 Mon Sep 17 00:00:00 2001
|
|
From: Ismael Luceno <ismael@iodev.co.uk>
|
|
Date: Sun, 15 Aug 2021 17:51:57 +0200
|
|
Subject: [PATCH] define NULL as nullptr when used in C++11 or later
|
|
|
|
This should be safer for casting and more compatible with existing code
|
|
bases that wrongly assume it must be defined as a pointer.
|
|
---
|
|
include/locale.h | 4 +++-
|
|
include/stddef.h | 4 +++-
|
|
include/stdio.h | 4 +++-
|
|
include/stdlib.h | 4 +++-
|
|
include/string.h | 4 +++-
|
|
include/time.h | 4 +++-
|
|
include/unistd.h | 4 +++-
|
|
include/wchar.h | 4 +++-
|
|
8 files changed, 24 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/include/locale.h b/include/locale.h
|
|
index ce384381c..11106fea8 100644
|
|
--- a/include/locale.h
|
|
+++ b/include/locale.h
|
|
@@ -7,7 +7,9 @@ extern "C" {
|
|
|
|
#include <features.h>
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/stddef.h b/include/stddef.h
|
|
index bd7538535..f25b86396 100644
|
|
--- a/include/stddef.h
|
|
+++ b/include/stddef.h
|
|
@@ -1,7 +1,9 @@
|
|
#ifndef _STDDEF_H
|
|
#define _STDDEF_H
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/stdio.h b/include/stdio.h
|
|
index 3604198c3..d1ed01f03 100644
|
|
--- a/include/stdio.h
|
|
+++ b/include/stdio.h
|
|
@@ -25,7 +25,9 @@ extern "C" {
|
|
|
|
#include <bits/alltypes.h>
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/stdlib.h b/include/stdlib.h
|
|
index 7af86e3bc..b507ca33b 100644
|
|
--- a/include/stdlib.h
|
|
+++ b/include/stdlib.h
|
|
@@ -7,7 +7,9 @@ extern "C" {
|
|
|
|
#include <features.h>
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/string.h b/include/string.h
|
|
index 795a2abcd..43ad0942e 100644
|
|
--- a/include/string.h
|
|
+++ b/include/string.h
|
|
@@ -7,7 +7,9 @@ extern "C" {
|
|
|
|
#include <features.h>
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/time.h b/include/time.h
|
|
index 5494df183..3d9483720 100644
|
|
--- a/include/time.h
|
|
+++ b/include/time.h
|
|
@@ -7,7 +7,9 @@ extern "C" {
|
|
|
|
#include <features.h>
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/unistd.h b/include/unistd.h
|
|
index 130640260..ee2dbe8af 100644
|
|
--- a/include/unistd.h
|
|
+++ b/include/unistd.h
|
|
@@ -15,7 +15,9 @@ extern "C" {
|
|
#define SEEK_CUR 1
|
|
#define SEEK_END 2
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
diff --git a/include/wchar.h b/include/wchar.h
|
|
index 88eb55b18..ed5d774df 100644
|
|
--- a/include/wchar.h
|
|
+++ b/include/wchar.h
|
|
@@ -38,7 +38,9 @@ extern "C" {
|
|
#define WCHAR_MIN (-1-0x7fffffff+L'\0')
|
|
#endif
|
|
|
|
-#ifdef __cplusplus
|
|
+#if __cplusplus >= 201103L
|
|
+#define NULL nullptr
|
|
+#elif defined(__cplusplus)
|
|
#define NULL 0L
|
|
#else
|
|
#define NULL ((void*)0)
|
|
|