nixos/manual: Must disable secure boot on UEFI installs (#364406)
[NixPkgs.git] / pkgs / os-specific / darwin / apple-source-releases / file_cmds / patches / 0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch
blobd54ac1fbd295e92d10402078315bbaec7ade2557
1 From 9d21ed4cb6b56966a7962227a33c0e1986996cb1 Mon Sep 17 00:00:00 2001
2 From: Randy Eckenrode <randy@largeandhighquality.com>
3 Date: Sun, 8 Sep 2024 09:46:49 -0400
4 Subject: [PATCH 3/3] Add implementations of missing APIs for older SDKs
6 ---
7 compat/rpmatch_compat.c | 10 ++++++++++
8 compat/rpmatch_compat.h | 6 ++++++
9 compat/time_compat.c | 38 ++++++++++++++++++++++++++++++++++++++
10 compat/time_compat.h | 16 ++++++++++++++++
11 4 files changed, 70 insertions(+)
12 create mode 100644 compat/rpmatch_compat.c
13 create mode 100644 compat/rpmatch_compat.h
14 create mode 100644 compat/time_compat.c
15 create mode 100644 compat/time_compat.h
17 diff --git a/compat/rpmatch_compat.c b/compat/rpmatch_compat.c
18 new file mode 100644
19 index 0000000..8eb99c3
20 --- /dev/null
21 +++ b/compat/rpmatch_compat.c
22 @@ -0,0 +1,10 @@
23 +// SPDX-License-Identifier: APSL-2.0
24 +// utimensat written by Randy Eckenrode © 2024
26 +#include "rpmatch_compat.h"
28 +#include <stdlib.h>
30 +int rpmatch(const char *response) {
31 + return response != NULL && (response[0] == 'y' || response[0] == 'Y');
33 diff --git a/compat/rpmatch_compat.h b/compat/rpmatch_compat.h
34 new file mode 100644
35 index 0000000..a13b64b
36 --- /dev/null
37 +++ b/compat/rpmatch_compat.h
38 @@ -0,0 +1,6 @@
39 +// SPDX-License-Identifier: APSL-2.0
40 +// utimensat written by Randy Eckenrode © 2024
42 +#pragma once
44 +extern int rpmatch(const char *response);
45 diff --git a/compat/time_compat.c b/compat/time_compat.c
46 new file mode 100644
47 index 0000000..becf778
48 --- /dev/null
49 +++ b/compat/time_compat.c
50 @@ -0,0 +1,38 @@
51 +// SPDX-License-Identifier: APSL-2.0
52 +// utimensat written by Randy Eckenrode © 2024
54 +#include "time_compat.h"
56 +#define futimens gzip_futimens
57 +#include "gzip/futimens.c"
58 +#undef futimens
60 +#include <sys/fcntl.h>
61 +#include <unistd.h>
63 +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
64 +extern int utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags);
65 +extern int futimens(int fd, const struct timespec times[_Nullable 2]);
66 +#endif
68 +int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags) {
69 + if (__builtin_available(macOS 10.13, *)) {
70 + return utimensat(dirfd, pathname, times, flags);
71 + } else {
72 + int fd = openat(dirfd, pathname, flags);
73 + if (fd == -1) { return -1; }
75 + int retval = compat_futimens(fd, times);
76 + if (close(fd) == -1) { return -1; }
78 + return retval;
79 + }
82 +int compat_futimens(int fd, const struct timespec times[_Nullable 2]) {
83 + if (__builtin_available(macOS 10.13, *)) {
84 + return futimens(fd, times);
85 + } else {
86 + return gzip_futimens(fd, times);
87 + }
89 diff --git a/compat/time_compat.h b/compat/time_compat.h
90 new file mode 100644
91 index 0000000..f07a7ed
92 --- /dev/null
93 +++ b/compat/time_compat.h
94 @@ -0,0 +1,16 @@
95 +// SPDX-License-Identifier: APSL-2.0
96 +// utimensat written by Randy Eckenrode © 2024
98 +#pragma once
100 +#include <time.h>
102 +// https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/sys/stat.h#L578-L579
103 +#define UTIME_NOW -1
104 +#define UTIME_OMIT -2
106 +#define utimensat compat_utimensat
107 +#define futimens compat_futimens
109 +extern int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags);
110 +extern int compat_futimens(int fd, const struct timespec times[_Nullable 2]);
112 2.46.0