commit 407b6e3a0cf4915ded460ee3f2ca101ae2e05d28
parent 62522c0ef37d7f4431331f429367467537948340
Author: Chris Bracken <chris@bracken.jp>
Date: Sat, 21 Feb 2026 08:00:45 +0900
openbsd: only include on necessary platforms
Diffstat:
7 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/BUILD.gn b/BUILD.gn
@@ -9,6 +9,7 @@ config("gout_config") {
"_XOPEN_SOURCE=700",
"_DEFAULT_SOURCE",
"_BSD_SOURCE",
+ "_DARWIN_C_SOURCE",
]
libs = [ "git2" ]
configs = [
diff --git a/third_party/openbsd/reallocarray.c b/third_party/openbsd/reallocarray.c
@@ -21,6 +21,9 @@
#include "reallocarray.h"
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__)
+
/*
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
@@ -35,3 +38,5 @@ void* reallocarray(void* optr, size_t nmemb, size_t size) {
}
return realloc(optr, size * nmemb);
}
+
+#endif
diff --git a/third_party/openbsd/reallocarray.h b/third_party/openbsd/reallocarray.h
@@ -3,7 +3,9 @@
#include <stdlib.h>
-#undef reallocarray
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__)
void* reallocarray(void* optr, size_t nmemb, size_t size);
+#endif
#endif // OPENBSD_REALLOCARRAY_H_
diff --git a/third_party/openbsd/strlcat.c b/third_party/openbsd/strlcat.c
@@ -21,6 +21,9 @@
#include "strlcat.h"
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__) && !defined(__APPLE__)
+
/*
* Appends src to string dst of size dsize (unlike strncat, dsize is the
* full size of dst, not space left). At most dsize-1 characters
@@ -55,3 +58,5 @@ size_t strlcat(char* dst, const char* src, size_t dsize) {
return (dlen + (src - osrc)); /* count does not include NUL */
}
+
+#endif
diff --git a/third_party/openbsd/strlcat.h b/third_party/openbsd/strlcat.h
@@ -1,9 +1,12 @@
#ifndef OPENBSD_STRLCAT_H_
#define OPENBSD_STRLCAT_H_
-#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
-#undef strlcat
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__) && !defined(__APPLE__)
size_t strlcat(char* dst, const char* src, size_t dsize);
+#endif
#endif // OPENBSD_STRLCAT_H_
diff --git a/third_party/openbsd/strlcpy.c b/third_party/openbsd/strlcpy.c
@@ -20,6 +20,9 @@
#include "strlcpy.h"
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__) && !defined(__APPLE__)
+
/*
* Copy string src to buffer dst of size dsize. At most dsize-1
* chars will be copied. Always NUL terminates (unless dsize == 0).
@@ -49,3 +52,5 @@ size_t strlcpy(char* dst, const char* src, size_t dsize) {
return (src - osrc - 1); /* count does not include NUL */
}
+
+#endif
diff --git a/third_party/openbsd/strlcpy.h b/third_party/openbsd/strlcpy.h
@@ -1,9 +1,12 @@
#ifndef OPENBSD_STRLCPY_H_
#define OPENBSD_STRLCPY_H_
-#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
-#undef strlcpy
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
+ !defined(__DragonFly__) && !defined(__APPLE__)
size_t strlcpy(char* dst, const char* src, size_t dsize);
+#endif
#endif // OPENBSD_STRLCPY_H_