darwin.mail_cmds: remove code for macOS < 11

This commit is contained in:
Emily
2024-11-18 00:14:01 +00:00
parent ba01760b21
commit 5cf94b53c8
3 changed files with 0 additions and 141 deletions
@@ -9,28 +9,10 @@ project('mail_cmds', 'c', version : '@version@')
cc = meson.get_compiler('c')
# Compatibility tests
utimensat_test = '''
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
int main(int argc, char* argv[]) {
return utimensat(AT_FDCWD, NULL, NULL, 0);
}
'''
has_utimensat = cc.compiles(utimensat_test, name : 'supports utimensat')
utimensat_c_args = has_utimensat ? [ ] : [ '-include', 'time_compat.h', '-I' + meson.source_root() + '/compat' ]
utimensat_sources = has_utimensat ? [ ] : [ 'compat/time_compat.c' ]
compat_link_args = not has_utimensat ? [ '-Wl,-undefined,dynamic_lookup' ] : [ ]
# Binaries
executable(
'mail',
c_args : utimensat_c_args,
install : true,
link_args : compat_link_args,
sources : [
'mail/cmd1.c',
'mail/cmd2.c',
@@ -55,7 +37,6 @@ executable(
'mail/v7.local.c',
'mail/vars.c',
'mail/version.c',
utimensat_sources,
],
)
install_man('mail/mail.1')
@@ -16,14 +16,5 @@ mkAppleDerivation {
xcodeHash = "sha256-6rBflDgQkqWDc8XPLgKIO703bMamg2QlhUnP71hBX3I=";
patches = [
# Add implementations of missing functions for older SDKs
./patches/0003-Add-implementations-of-missing-APIs-for-older-SDKs.patch
];
postPatch = ''
cp '${file_cmds.src}/gzip/futimens.c' compat/futimens.c
'';
meta.description = "Traditional mail command for Darwin";
}
@@ -1,113 +0,0 @@
From 9d21ed4cb6b56966a7962227a33c0e1986996cb1 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Sun, 8 Sep 2024 09:46:49 -0400
Subject: [PATCH 3/3] Add implementations of missing APIs for older SDKs
---
compat/rpmatch_compat.c | 10 ++++++++++
compat/rpmatch_compat.h | 6 ++++++
compat/time_compat.c | 38 ++++++++++++++++++++++++++++++++++++++
compat/time_compat.h | 16 ++++++++++++++++
4 files changed, 70 insertions(+)
create mode 100644 compat/rpmatch_compat.c
create mode 100644 compat/rpmatch_compat.h
create mode 100644 compat/time_compat.c
create mode 100644 compat/time_compat.h
diff --git a/compat/rpmatch_compat.c b/compat/rpmatch_compat.c
new file mode 100644
index 0000000..8eb99c3
--- /dev/null
+++ b/compat/rpmatch_compat.c
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: APSL-2.0
+// utimensat written by Randy Eckenrode © 2024
+
+#include "rpmatch_compat.h"
+
+#include <stdlib.h>
+
+int rpmatch(const char *response) {
+ return response != NULL && (response[0] == 'y' || response[0] == 'Y');
+}
diff --git a/compat/rpmatch_compat.h b/compat/rpmatch_compat.h
new file mode 100644
index 0000000..a13b64b
--- /dev/null
+++ b/compat/rpmatch_compat.h
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: APSL-2.0
+// utimensat written by Randy Eckenrode © 2024
+
+#pragma once
+
+extern int rpmatch(const char *response);
diff --git a/compat/time_compat.c b/compat/time_compat.c
new file mode 100644
index 0000000..becf778
--- /dev/null
+++ b/compat/time_compat.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: APSL-2.0
+// utimensat written by Randy Eckenrode © 2024
+
+#include "time_compat.h"
+
+#define futimens gzip_futimens
+#include "compat/futimens.c"
+#undef futimens
+
+#include <sys/fcntl.h>
+#include <unistd.h>
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+extern int utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags);
+extern int futimens(int fd, const struct timespec times[_Nullable 2]);
+#endif
+
+int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags) {
+ if (__builtin_available(macOS 10.13, *)) {
+ return utimensat(dirfd, pathname, times, flags);
+ } else {
+ int fd = openat(dirfd, pathname, flags);
+ if (fd == -1) { return -1; }
+
+ int retval = compat_futimens(fd, times);
+ if (close(fd) == -1) { return -1; }
+
+ return retval;
+ }
+}
+
+int compat_futimens(int fd, const struct timespec times[_Nullable 2]) {
+ if (__builtin_available(macOS 10.13, *)) {
+ return futimens(fd, times);
+ } else {
+ return gzip_futimens(fd, times);
+ }
+}
diff --git a/compat/time_compat.h b/compat/time_compat.h
new file mode 100644
index 0000000..f07a7ed
--- /dev/null
+++ b/compat/time_compat.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: APSL-2.0
+// utimensat written by Randy Eckenrode © 2024
+
+#pragma once
+
+#include <time.h>
+
+// https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/bsd/sys/stat.h#L578-L579
+#define UTIME_NOW -1
+#define UTIME_OMIT -2
+
+#define utimensat compat_utimensat
+#define futimens compat_futimens
+
+extern int compat_utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags);
+extern int compat_futimens(int fd, const struct timespec times[_Nullable 2]);
--
2.46.0