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
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
19 index 0000000..8eb99c3
21 +++ b/compat/rpmatch_compat.c
23 +// SPDX-License-Identifier: APSL-2.0
24 +// utimensat written by Randy Eckenrode © 2024
26 +#include "rpmatch_compat.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
35 index 0000000..a13b64b
37 +++ b/compat/rpmatch_compat.h
39 +// SPDX-License-Identifier: APSL-2.0
40 +// utimensat written by Randy Eckenrode © 2024
44 +extern int rpmatch(const char *response);
45 diff --git a/compat/time_compat.c b/compat/time_compat.c
47 index 0000000..becf778
49 +++ b/compat/time_compat.c
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"
60 +#include <sys/fcntl.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]);
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);
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; }
82 +int compat_futimens(int fd, const struct timespec times[_Nullable 2]) {
83 + if (__builtin_available(macOS 10.13, *)) {
84 + return futimens(fd, times);
86 + return gzip_futimens(fd, times);
89 diff --git a/compat/time_compat.h b/compat/time_compat.h
91 index 0000000..f07a7ed
93 +++ b/compat/time_compat.h
95 +// SPDX-License-Identifier: APSL-2.0
96 +// utimensat written by Randy Eckenrode © 2024
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]);