├── test ├── test_stat.c_link ├── test_packet_nocancel.c ├── test_packet_nofix_nocancel.c ├── test_packet_nofix.c ├── test_stat_ino64.c ├── test_getentropy.c ├── test_packet_nonposix.c ├── test_attrlist_nonposix.c ├── test_fdopendir_nonposix.c ├── test_realpath_nonposix.c ├── test_packet_nofix_nonposix.c ├── test_stat_ino32.c ├── test_fdopendir_ino32.c ├── test_open_memstream.c ├── test_realpath_compat.c ├── test_fdopendir_ino64.c ├── test_netif_includes_syssocket.c ├── test_sincos.c ├── test_renameat.c ├── README-CPP.txt ├── test_realpath_nonext.c ├── test_os_unfair_lock.c ├── test_dirfuncs_compat.c ├── test_pthread_rwlock_basic.c ├── test_symbol_aliases.c ├── test_pthread_get_stacksize_np.c ├── test_flsl.c ├── test_ffsl.c └── test_stpncpy.c ├── manual_tests ├── allheaders.h ├── revheaders.h ├── allheaders_cpp.cpp ├── revheaders_cpp.cpp ├── libtest_stpncpy_chk_force0.c ├── libtest_stpncpy_chk_force1.c ├── libtest_stpncpy_chk_forced.c ├── checksdkincludes.sh ├── libtest_packet_cont.c ├── headerinfo.c └── checksdkversion.c ├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── xtest ├── test_allheaders_199309.c ├── test_allheaders_200809.c ├── test_scandir_old.c ├── test_allheaders_full.c ├── test_darwin_c_199309.c ├── test_darwin_c_200809.c ├── test_allheaders_199309_ds.c ├── test_allheaders_200809_ds.c ├── test_darwin_c_full.c ├── test_allheaders_full_ds.c ├── test_assert.c ├── test_scandir_ino32.c ├── test_scandir_ino64.c ├── allheaders.h ├── revheaders.h ├── test_allheaders.c ├── test_revheaders.c ├── test_usb.c ├── test_utunh.c ├── test_dirent.c ├── test_cputypes.c └── test_math_h.c ├── tools ├── getversionmacros.sh ├── binarchs.sh ├── checkarchprog.sh ├── archrun.sh ├── allheaders.sh └── runnablearchs.sh ├── src ├── filesec_internal.h ├── dummylib.xxc ├── Makefile ├── pthread_setname_np.c ├── wcpcpy_family.c ├── dirfuncs_compat.h ├── compiler.h ├── wcsnlen.c ├── getline.h ├── strndup.h ├── getdelim.h ├── endian.h ├── wcsdup.c ├── getline.c ├── lchmod.c ├── clonefile.c ├── strnlen.h ├── os_unfair_lock.c ├── wcscasecmp_family.c ├── symbol_aliases.c ├── util.h ├── strnlen.c ├── quarantine.h ├── strndup.c ├── getentropy.c ├── lutimes.c ├── memmem.c ├── dirfuncs_compat.c ├── stpncpy_chk.c ├── sincos.c ├── stpncpy.c ├── strings.c ├── posix_memalign_emulation.c ├── pthread_get_stacksize_np.c ├── fsgetpath.c └── pthread_chdir.c ├── include ├── assert.h ├── mach │ ├── machine.h │ └── mach_time.h ├── netdb.h ├── pthread_impl.h ├── sys │ ├── attr.h │ ├── mman.h │ ├── time.h │ ├── spawn.h │ ├── fsgetpath.h │ ├── stdio.h │ ├── clonefile.h │ ├── aio.h │ ├── fcntl.h │ ├── random.h │ └── queue.h ├── uuid │ └── uuid.h ├── net │ ├── if.h │ └── if_utun.h ├── CoreFoundation │ └── CoreFoundation.h ├── IOKit │ └── usb │ │ └── USB.h ├── available.h ├── OpenGL │ └── gliDispatch.h ├── secure │ └── _common.h ├── libkern │ └── OSAtomic.h ├── xlocale │ └── _wchar.h ├── pthread.h ├── strings.h ├── os │ └── lock.h ├── wchar.h ├── AvailabilityMacros.h ├── _macports_extras │ └── tiger_leopard │ │ └── net │ │ └── if_utun.h ├── MacTypes.h ├── stdlib.h ├── copyfile.h └── cmath ├── disabled └── README.txt └── LICENSE /test/test_stat.c_link: -------------------------------------------------------------------------------- 1 | test_stat.c -------------------------------------------------------------------------------- /manual_tests/allheaders.h: -------------------------------------------------------------------------------- 1 | ../xtest/allheaders.h -------------------------------------------------------------------------------- /manual_tests/revheaders.h: -------------------------------------------------------------------------------- 1 | ../xtest/revheaders.h -------------------------------------------------------------------------------- /manual_tests/allheaders_cpp.cpp: -------------------------------------------------------------------------------- 1 | ../xtest/test_allheaders.c -------------------------------------------------------------------------------- /manual_tests/revheaders_cpp.cpp: -------------------------------------------------------------------------------- 1 | ../xtest/test_revheaders.c -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: macports 2 | github: macports 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | bin 3 | lib 4 | xlib 5 | tst_data 6 | tbin 7 | tlbin 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | os: osx 3 | script: make && sudo make install && make test 4 | -------------------------------------------------------------------------------- /test/test_packet_nocancel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_packet with NOCANCEL variant. 3 | */ 4 | 5 | #define __DARWIN_NON_CANCELABLE 1 6 | #include "test_packet.c" 7 | -------------------------------------------------------------------------------- /xtest/test_allheaders_199309.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to 199309L-1. 3 | */ 4 | 5 | #define _POSIX_C_SOURCE (199309L-1) 6 | 7 | #include "test_allheaders.c" 8 | -------------------------------------------------------------------------------- /xtest/test_allheaders_200809.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to 200809L-1. 3 | */ 4 | 5 | #define _POSIX_C_SOURCE (200809L-1) 6 | 7 | #include "test_allheaders.c" 8 | -------------------------------------------------------------------------------- /manual_tests/libtest_stpncpy_chk_force0.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of stpncpy_chk with enable forced to 0 (to disable checks). 3 | */ 4 | 5 | #define _FORTIFY_SOURCE 0 6 | 7 | #include "libtest_stpncpy_chk.c" 8 | -------------------------------------------------------------------------------- /manual_tests/libtest_stpncpy_chk_force1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of stpncpy_chk with enable forced to 1 (not the usual 2). 3 | */ 4 | 5 | #define _FORTIFY_SOURCE 1 6 | 7 | #include "libtest_stpncpy_chk.c" 8 | -------------------------------------------------------------------------------- /xtest/test_scandir_old.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_scandir with _MACPORTS_LEGACY_COMPATIBLE_SCANDIR disabled. 3 | */ 4 | 5 | #define _MACPORTS_LEGACY_COMPATIBLE_SCANDIR 0 6 | 7 | #include "test_scandir.c" 8 | -------------------------------------------------------------------------------- /test/test_packet_nofix_nocancel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of no-fix test_packet with NOCANCEL variant. 3 | */ 4 | 5 | #define _MACPORTS_LEGACY_DISABLE_CMSG_FIXES 1 6 | #define __DARWIN_NON_CANCELABLE 1 7 | 8 | #include "test_packet.c" 9 | -------------------------------------------------------------------------------- /xtest/test_allheaders_full.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to __DARWIN_C_FULL-1. 3 | */ 4 | 5 | /* Use assumed __DARWIN_C_FULL value */ 6 | #define _POSIX_C_SOURCE (900000L-1) 7 | 8 | #include "test_allheaders.c" 9 | -------------------------------------------------------------------------------- /xtest/test_darwin_c_199309.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_darwin_c with __DARWIN_C_LEVEL set to 199309L-1. 3 | */ 4 | 5 | /* Set __DARWIN_C_LEVEL indirectly (can't be set directly) */ 6 | #define _POSIX_C_SOURCE (199309L-1) 7 | 8 | #include "test_darwin_c.c" 9 | -------------------------------------------------------------------------------- /xtest/test_darwin_c_200809.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_darwin_c with __DARWIN_C_LEVEL set to 200809L-1. 3 | */ 4 | 5 | /* Set __DARWIN_C_LEVEL indirectly (can't be set directly) */ 6 | #define _POSIX_C_SOURCE (200809L-1) 7 | 8 | #include "test_darwin_c.c" 9 | -------------------------------------------------------------------------------- /test/test_packet_nofix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_packet with CMSG fixes disabled. 3 | * 4 | * This provides a way to test the feature for disabling the fixes. 5 | */ 6 | 7 | #define _MACPORTS_LEGACY_DISABLE_CMSG_FIXES 1 8 | 9 | #include "test_packet.c" 10 | -------------------------------------------------------------------------------- /xtest/test_allheaders_199309_ds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to 199309L-1, 3 | * and _DARWIN_C_SOURCE defined. 4 | */ 5 | 6 | #define _POSIX_C_SOURCE (199309L-1) 7 | #define _DARWIN_C_SOURCE 8 | 9 | #include "test_allheaders.c" 10 | -------------------------------------------------------------------------------- /xtest/test_allheaders_200809_ds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to 200809L-1, 3 | * and _DARWIN_C_SOURCE defined. 4 | */ 5 | 6 | #define _POSIX_C_SOURCE (200809L-1) 7 | #define _DARWIN_C_SOURCE 8 | 9 | #include "test_allheaders.c" 10 | -------------------------------------------------------------------------------- /test/test_stat_ino64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_stat with 64-bit inodes (if possible). 3 | * 4 | * This is primarily for 10.5, where 64-bit inodes are supported 5 | * but not the default. 6 | */ 7 | 8 | #define _DARWIN_USE_64_BIT_INODE 1 9 | 10 | #include "test_stat.c" 11 | -------------------------------------------------------------------------------- /tools/getversionmacros.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Script to extract list of version macros from SDK, and convert to #undefs 3 | 4 | SDKROOT="$1" 5 | 6 | grep MAC_OS_VERSION_ $SDKROOT/usr/include/AvailabilityVersions.h | sed -E 's/^#define +MAC_OS_VERSION_([0-9_]+).*/#undef MAC_OS_VERSION_\1/' 7 | -------------------------------------------------------------------------------- /xtest/test_darwin_c_full.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_darwin_c with __DARWIN_C_LEVEL set to __DARWIN_C_FULL-1. 3 | */ 4 | 5 | /* Set __DARWIN_C_LEVEL indirectly (can't be set directly) */ 6 | /* Use assumed __DARWIN_C_FULL value */ 7 | #define _POSIX_C_SOURCE (900000L-1) 8 | 9 | #include "test_darwin_c.c" 10 | -------------------------------------------------------------------------------- /xtest/test_allheaders_full_ds.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_allheaders with _POSIX_C_SOURCE set to __DARWIN_C_FULL-1, 3 | * and _DARWIN_C_SOURCE defined. 4 | */ 5 | 6 | /* Use assumed __DARWIN_C_FULL value */ 7 | #define _POSIX_C_SOURCE (900000L-1) 8 | #define _DARWIN_C_SOURCE 9 | 10 | #include "test_allheaders.c" 11 | -------------------------------------------------------------------------------- /tools/binarchs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Get architectures for system programs. 4 | # NOTE: Currently needed to build 'which' on 10.4. 5 | 6 | REFPROG="${1:-/usr/bin/true}" 7 | 8 | ARCHS="$(file $REFPROG | grep ' executable ' | sed 's|.* executable ||')" 9 | ARCHFLAGS="$(for a in $ARCHS; do echo -n ' -arch' $a; done)" 10 | 11 | echo $ARCHFLAGS 12 | -------------------------------------------------------------------------------- /test/test_getentropy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple test harness and benchmark for MT Arc4Random 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int 12 | main() 13 | { 14 | char buf[8]; 15 | int r = getentropy(&buf, sizeof buf); 16 | assert(r == 0); 17 | printf( "getentropy : %i\n", r ); 18 | return r; 19 | } 20 | -------------------------------------------------------------------------------- /manual_tests/libtest_stpncpy_chk_forced.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of stpncpy_chk with enable forced on. 3 | * 4 | * The security wrapper mechanism is unavailable on 10.4, available but 5 | * defaulted off in 10.5, and enabled and defaulted on in 10.6+. 6 | * Overriding the default here enables it on 10.5, with no effect on other 7 | * OS versions. 8 | */ 9 | 10 | #define _FORTIFY_SOURCE 2 11 | 12 | #include "libtest_stpncpy_chk.c" 13 | -------------------------------------------------------------------------------- /test/test_packet_nonposix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_packet with non-POSIX semantics (32-bit only). 3 | * 4 | * Attempting a 64-bit build with _NONSTD_SOURCE results in an error. 5 | */ 6 | 7 | #if defined(__LP64__) && __LP64__ 8 | 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | (void) argc; 16 | printf("%s is inapplicable.\n", basename(argv[0])); 17 | return 0; 18 | } 19 | 20 | #else /* 32-bit */ 21 | 22 | #define _NONSTD_SOURCE 23 | #include "test_packet.c" 24 | 25 | #endif /* 32-bit */ 26 | -------------------------------------------------------------------------------- /src/filesec_internal.h: -------------------------------------------------------------------------------- 1 | /* Layout of filesec_t struct, solely for debugging. */ 2 | 3 | #include 4 | #include 5 | 6 | struct _filesec { 7 | int fs_valid; 8 | #define FS_VALID_UID (1<<0) 9 | #define FS_VALID_GID (1<<1) 10 | #define FS_VALID_UUID (1<<2) 11 | #define FS_VALID_GRPUUID (1<<3) 12 | #define FS_VALID_MODE (1<<4) 13 | #define FS_VALID_ACL (1<<5) 14 | uid_t fs_uid; 15 | gid_t fs_gid; 16 | uuid_t fs_uuid; 17 | uuid_t fs_grpuuid; 18 | mode_t fs_mode; 19 | size_t fs_aclsize; 20 | void *fs_aclbuf; 21 | }; 22 | -------------------------------------------------------------------------------- /test/test_attrlist_nonposix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_realpath with non-POSIX semantics (32-bit only). 3 | * 4 | * Attempting a 64-bit build with _NONSTD_SOURCE results in an error. 5 | */ 6 | 7 | #if defined(__LP64__) && __LP64__ 8 | 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | (void) argc; 16 | printf("%s is inapplicable.\n", basename(argv[0])); 17 | return 0; 18 | } 19 | 20 | #else /* 32-bit */ 21 | 22 | #define _NONSTD_SOURCE 23 | #include "test_attrlist.c" 24 | 25 | #endif /* 32-bit */ 26 | -------------------------------------------------------------------------------- /test/test_fdopendir_nonposix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_fdopendir with non-POSIX semantics (32-bit only). 3 | * 4 | * Attempting a 64-bit build with _NONSTD_SOURCE results in an error. 5 | */ 6 | 7 | #if defined(__LP64__) && __LP64__ 8 | 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | (void) argc; 16 | printf("%s is inapplicable.\n", basename(argv[0])); 17 | return 0; 18 | } 19 | 20 | #else /* 32-bit */ 21 | 22 | #define _NONSTD_SOURCE 23 | #include "test_fdopendir.c" 24 | 25 | #endif /* 32-bit */ 26 | -------------------------------------------------------------------------------- /test/test_realpath_nonposix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_realpath with non-POSIX semantics (32-bit only). 3 | * 4 | * Attempting a 64-bit build with _NONSTD_SOURCE results in an error. 5 | */ 6 | 7 | #if defined(__LP64__) && __LP64__ 8 | 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | (void) argc; 16 | printf("%s is inapplicable.\n", basename(argv[0])); 17 | return 0; 18 | } 19 | 20 | #else /* 32-bit */ 21 | 22 | #define _NONSTD_SOURCE 23 | #include "test_realpath.c" 24 | 25 | #endif /* 32-bit */ 26 | -------------------------------------------------------------------------------- /manual_tests/checksdkincludes.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Script to verify that files referencing __MPLS_SDK_* are including 4 | # _macports_extras/sdkversion.h. 5 | # 6 | # The optional argument is a git commit to apply the test to. 7 | 8 | ID="$1" 9 | 10 | HEADER="sdkversion.h" 11 | HEADERINC="_macports_extras/$HEADER" 12 | HEADERPATH="include/$HEADERINC" 13 | 14 | FILES="$(git grep -l '__MPLS_SDK_' $ID | grep -v ^$HEADERPATH)" 15 | 16 | for f in $FILES; do 17 | if ! git grep -q "$HEADERINC" $ID -- "$f"; then 18 | echo "\"#include <$HEADERINC>\" is missing from $f" 19 | ! break 20 | fi 21 | done 22 | -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | 2 | /* Include the primary system assert.h */ 3 | #include_next 4 | 5 | 6 | /* now add the missing definition of static_assert for C11 code, added to the 10.11 SDK. */ 7 | /* if a newer assert.h header has already done this in a modern SDK, then */ 8 | /* _ASSERT_H_ will be defined and will block this */ 9 | 10 | #ifndef _ASSERT_H_ 11 | #define _ASSERT_H_ 12 | 13 | #ifndef __cplusplus 14 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 15 | #define static_assert _Static_assert 16 | #endif /* __STDC_VERSION__ */ 17 | #endif /* !__cplusplus */ 18 | 19 | #endif /* _ASSERT_H_ */ 20 | -------------------------------------------------------------------------------- /src/dummylib.xxc: -------------------------------------------------------------------------------- 1 | /* dummylib - mostly empty item containing one global definition. */ 2 | /* 3 | * When the legacy-support library becomes logically empty, it still needs 4 | * to contain at least one object to keep the tools happy. It also needs 5 | * to define at least one global to avoid "no symbols" warnings. This 6 | * source is used to provide such an object. Currently this happens on 7 | * 10.15+. 8 | * 9 | * This source is actually C, but uses a different extension to defend 10 | * against wildcarding in the Makefile. 11 | */ 12 | 13 | int __LEGACY_SUPPORT_LIBRARY_IS_INTENTIONALLY_LEFT_BLANK__ = 0; 14 | -------------------------------------------------------------------------------- /xtest/test_assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | (void) argc; (void) argv; 8 | 9 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201100 10 | static_assert(1, "true"); 11 | printf("static_assert compiled successfully in C11 mode\n"); 12 | #elif defined(__STDC_VERSION__) 13 | printf("static_assert is unavailable before C11, __STDC_VERSION__ = %d\n", 14 | (int) __STDC_VERSION__); 15 | #else 16 | printf("static_assert is unavailable before C11," 17 | " __STDC_VERSION__ is undefined\n"); 18 | #endif 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/test_packet_nofix_nonposix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_packet with non-POSIX semantics (32-bit only). 3 | * 4 | * Attempting a 64-bit build with _NONSTD_SOURCE results in an error. 5 | */ 6 | 7 | #if defined(__LP64__) && __LP64__ 8 | 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) 14 | { 15 | (void) argc; 16 | printf("%s is inapplicable.\n", basename(argv[0])); 17 | return 0; 18 | } 19 | 20 | #else /* 32-bit */ 21 | 22 | #define _MACPORTS_LEGACY_DISABLE_CMSG_FIXES 1 23 | #define _NONSTD_SOURCE 24 | 25 | #include "test_packet.c" 26 | 27 | #endif /* 32-bit */ 28 | -------------------------------------------------------------------------------- /manual_tests/libtest_packet_cont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_packet with secret SO_TIMESTAMP_CONTINUOUS enabled. 3 | * 4 | * This exists in 10.14+ kernels, but isn't defined for userspace. 5 | */ 6 | 7 | /* Definitions from xnu/bsd/sys/socket_private.h */ 8 | /* With #ifndefs just in case some SDK decides to define them */ 9 | #ifndef SO_TIMESTAMP_CONTINUOUS 10 | #define SO_TIMESTAMP_CONTINUOUS 0x40000 /* Continuous monotonic timestamp on rcvd dgram */ 11 | #endif 12 | #ifndef SCM_TIMESTAMP_CONTINUOUS 13 | #define SCM_TIMESTAMP_CONTINUOUS 0x07 /* timestamp (uint64_t) */ 14 | #endif 15 | 16 | #include "../test/test_packet.c" 17 | -------------------------------------------------------------------------------- /test/test_stat_ino32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_stat with 32-bit inodes (if possible). 3 | * 4 | * This only works on ppc/x86. Later platforms (e.g. arm64) only 5 | * support 64-bit inodes. 6 | */ 7 | 8 | #if !defined(__ppc__) && !defined(__ppc64__) \ 9 | && !defined(__i386__) && !defined(__x86_64__) 10 | 11 | #include 12 | #include 13 | 14 | int 15 | main(int argc, char *argv[]) 16 | { 17 | (void) argc; 18 | printf("%s is only supported on ppc/x86.\n", basename(argv[0])); 19 | return 0; 20 | } 21 | 22 | #else /* ppc/x86 */ 23 | 24 | #define _DARWIN_NO_64_BIT_INODE 1 25 | 26 | #include "test_stat.c" 27 | 28 | #endif /* ppc/x86 */ 29 | -------------------------------------------------------------------------------- /xtest/test_scandir_ino32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_scandir with 32-bit inodes (if possible). 3 | * 4 | * This only works on ppc/x86. Later platforms (e.g. arm64) only 5 | * support 64-bit inodes. 6 | */ 7 | 8 | #if !defined(__ppc__) && !defined(__ppc64__) \ 9 | && !defined(__i386__) && !defined(__x86_64__) 10 | 11 | #include 12 | #include 13 | 14 | int 15 | main(int argc, char *argv[]) 16 | { 17 | (void) argc; 18 | printf("%s is only supported on ppc/x86.\n", basename(argv[0])); 19 | return 0; 20 | } 21 | 22 | #else /* ppc/x86 */ 23 | 24 | #define _DARWIN_NO_64_BIT_INODE 1 25 | 26 | #include "test_scandir.c" 27 | 28 | #endif /* ppc/x86 */ 29 | -------------------------------------------------------------------------------- /test/test_fdopendir_ino32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_fdopendir with 32-bit inodes (if possible). 3 | * 4 | * This only works on ppc/x86. Later platforms (e.g. arm64) only 5 | * support 64-bit inodes. 6 | */ 7 | 8 | #if !defined(__ppc__) && !defined(__ppc64__) \ 9 | && !defined(__i386__) && !defined(__x86_64__) 10 | 11 | #include 12 | #include 13 | 14 | int 15 | main(int argc, char *argv[]) 16 | { 17 | (void) argc; 18 | printf("%s is only supported on ppc/x86.\n", basename(argv[0])); 19 | return 0; 20 | } 21 | 22 | #else /* ppc/x86 */ 23 | 24 | #define _DARWIN_NO_64_BIT_INODE 1 25 | 26 | #include "test_fdopendir.c" 27 | 28 | #endif /* ppc/x86 */ 29 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # Simple Makefile for building copyfile as standalone program. 2 | 3 | copyfile: copyfile.c 4 | $(CC) -D_COPYFILE_TEST -I../include $^ -o $@ 5 | 6 | # No-quarantine version which works on 10.4 7 | copyfile-nq: copyfile.c 8 | $(CC) -D_COPYFILE_TEST -D_NO_QUARANTINE -I../include $^ -o $@ 9 | 10 | # Versions for debugging arch-related issues (10.4-compatible). 11 | DEBUG_FLAGS = -g3 -O0 -D_COPYFILE_TEST -D_COPYFILE_DEBUG -D_NO_QUARANTINE 12 | copyfile-ppc: copyfile.c 13 | $(CC) -arch ppc $(DEBUG_FLAGS) -I../include $^ -o $@ 14 | copyfile-i386: copyfile.c 15 | $(CC) -arch i386 $(DEBUG_FLAGS) -I../include $^ -o $@ 16 | 17 | copyfile-dbg: copyfile-ppc copyfile-i386 18 | 19 | .PHONY: copyfile-dbg 20 | -------------------------------------------------------------------------------- /test/test_open_memstream.c: -------------------------------------------------------------------------------- 1 | /*#include "memstream.h"*/ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | char *buffer = 0; 10 | size_t size = 0; 11 | FILE *fp = open_memstream(&buffer, &size); 12 | int i; 13 | for (i = 0; i < 10240; ++i) { 14 | static char c = 42; 15 | fflush(fp); 16 | assert(size == i); 17 | fwrite(&c, 1, 1, fp); 18 | } 19 | fclose(fp); 20 | assert(size == 10240); 21 | free(buffer); 22 | fp = open_memstream(&buffer, &size); 23 | fprintf(fp, "This is a test of memstream, from main at %p.\n", main); 24 | fclose(fp); 25 | fputs(buffer, stdout); 26 | free(buffer); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/test_realpath_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_realpath for compatibility entry. 3 | */ 4 | 5 | /* 6 | * This tests the macports_legacy_realpath() compatibility entry. 7 | * 8 | * For OS versions that never used the wrapper, this entire test is a dummy. 9 | * Because of that condition, this test is an exception to the rule that tests 10 | * shouldn't check the feature flags. 11 | */ 12 | 13 | /* MP support header */ 14 | #include "MacportsLegacySupport.h" 15 | #if __MPLS_LIB_SUPPORT_REALPATH_ALLOC__ 16 | 17 | #define TEST_MACPORTS_LEGACY_REALPATH 18 | 19 | #include "test_realpath.c" 20 | 21 | #else /* !__MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */ 22 | 23 | int main(){ return 0; } 24 | 25 | #endif /* !__MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */ 26 | -------------------------------------------------------------------------------- /xtest/test_scandir_ino64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_scandir with 64-bit inodes (if possible). 3 | * 4 | * This is primarily for 10.5, where 64-bit inodes are supported 5 | * but not the default. 6 | * 7 | * Currently, 64-bit-inode directory operations don't work on 10.4. 8 | */ 9 | 10 | #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \ 11 | || __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 12 | 13 | #include 14 | #include 15 | 16 | int 17 | main(int argc, char *argv[]) 18 | { 19 | (void) argc; 20 | printf("%s is unsupported on 10.4.\n", basename(argv[0])); 21 | return 0; 22 | } 23 | 24 | #else /* >= 10.5 */ 25 | 26 | #define _DARWIN_USE_64_BIT_INODE 1 27 | 28 | #include "test_scandir.c" 29 | 30 | #endif /* >= 10.5 */ 31 | -------------------------------------------------------------------------------- /test/test_fdopendir_ino64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_fdopendir with 64-bit inodes (if possible). 3 | * 4 | * This is primarily for 10.5, where 64-bit inodes are supported 5 | * but not the default. 6 | * 7 | * Currently, 64-bit-inode directory operations don't work on 10.4. 8 | */ 9 | 10 | #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \ 11 | || __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 12 | 13 | #include 14 | #include 15 | 16 | int 17 | main(int argc, char *argv[]) 18 | { 19 | (void) argc; 20 | printf("%s is unsupported on 10.4.\n", basename(argv[0])); 21 | return 0; 22 | } 23 | 24 | #else /* >= 10.5 */ 25 | 26 | #define _DARWIN_USE_64_BIT_INODE 1 27 | 28 | #include "test_fdopendir.c" 29 | 30 | #endif /* >= 10.5 */ 31 | -------------------------------------------------------------------------------- /disabled/README.txt: -------------------------------------------------------------------------------- 1 | The atexit.c source has been temporarily moved here until it can be fixed. 2 | The Portfile has been removing it all along, so this just makes the local 3 | build consistent with the port build. Since it's been disabled since 4 | its inception in Apr-2022, it clearly hasn't been missed much. Note that 5 | the relevant entries in add_symbols.c remain present, but that's also true 6 | of the way the Portfile was acting. 7 | 8 | It would be highly desirable to have reasonable tests for it before 9 | fixing and reactivating it. 10 | 11 | The Portfile block that this replaces (based on the old filename) is: 12 | 13 | pre-patch { 14 | # until upstream can be fixed, do not include atexit symbols 15 | # under certain circumstances, infinite recursive loops can form 16 | delete ${worksrcpath}/src/macports_legacy_atexit.c 17 | } 18 | -------------------------------------------------------------------------------- /test/test_netif_includes_syssocket.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | int main() 19 | { 20 | (void)sizeof(((struct ifreq *)0)->ifr_name); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tools/checkarchprog.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Check to see whether the 'arch' program accepts an arch argument, i.e. 4 | # whether it's a 10.5+ version of 'arch'. 5 | # 6 | # Note that the arch returned by 'arch' is 'i386' on 'x86_64' machines, 7 | # and may not be supported by some executables. So instead we use 8 | # the hw.machine sysctl parameter, which may also be 'i386' on 'x86_64' 9 | # machines, but is always a valid arch for system programs. Additionally, 10 | # it may return "Power Macintosh", which we have to replace with "ppc". 11 | # 12 | # The basic approach is to try using the obtained arch as an argument 13 | # to the 'arch' program targeting the 'true' program, which should succeed 14 | # unless the 'arch' program fails to accept the argument. We return either 15 | # the full path of the successful arch program, or nothing. 16 | 17 | ARCHPROG="$(which arch)" 18 | TESTARCH="$(sysctl -n hw.machine)" 19 | TESTPROG="$(which true)" 20 | 21 | if [ "$TESTARCH" == "Power Macintosh" ]; then TESTARCH=ppc; fi 22 | 23 | if "$ARCHPROG" "-$TESTARCH" "$TESTPROG" 2>/dev/null; then echo "$ARCHPROG"; fi 24 | -------------------------------------------------------------------------------- /include/mach/machine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* Include the primary system mach/machine.h */ 18 | #include_next 19 | 20 | #ifndef CPU_TYPE_ARM 21 | #define CPU_TYPE_ARM ((cpu_type_t) 12) 22 | #endif 23 | 24 | #ifndef CPU_SUBTYPE_ARM64E 25 | #define CPU_SUBTYPE_ARM64E ((cpu_subtype_t) 2) 26 | #endif 27 | -------------------------------------------------------------------------------- /include/netdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_NETDB_H_ 18 | #define _MACPORTS_NETDB_H_ 19 | /* Include the primary system netdb.h */ 20 | #include_next 21 | 22 | #ifndef AI_NUMERICSERV 23 | #define AI_NUMERICSERV 0x00001000 /* prevent service name resolution */ 24 | #endif 25 | 26 | #endif /* _MACPORTS_NETDB_H_ */ 27 | -------------------------------------------------------------------------------- /xtest/allheaders.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #ifdef __cplusplus 7 | #include 8 | #endif 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | -------------------------------------------------------------------------------- /xtest/revheaders.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #ifdef __cplusplus 37 | #include 38 | #endif 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | -------------------------------------------------------------------------------- /tools/archrun.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This is a replacement for the 'arch' program, intended to be used on 10.4 4 | # systems where 'arch' can't be used to specify an execution architecture. 5 | # 6 | # This works by using lipo to create a single-architecture copy of the target 7 | # executable, and then running that. 8 | # 9 | # A complication in principle (though it doesn't happen on 10.4, which is 10 | # the only OS where we expect to need this tool) is that on 10.5+, 'ppc' 11 | # slices are coded as 'ppc7400', which lipo doesn't recognize when asked 12 | # for 'ppc'. So we include a fallback invocation for 'ppc'->'ppc7400'. 13 | # We suppress the possible error message from the 'ppc' invocation, but if 14 | # the 'ppc7400' invocation also fails, we'll get an error message from that. 15 | 16 | ARCH="${1##-}" 17 | PROG="$2" 18 | shift 2 19 | ARGS="$@" 20 | 21 | DEST="$PROG-$ARCH" 22 | 23 | LIPO="/usr/bin/lipo" 24 | 25 | if [ "$ARCH" != 'ppc' ]; then 26 | $LIPO "$PROG" -thin "$ARCH" -output "$DEST" && exec "$DEST" "$ARGS" 27 | else 28 | $LIPO "$PROG" -thin ppc -output "$DEST" 2>/dev/null \ 29 | || $LIPO "$PROG" -thin ppc7400 -output "$DEST" && exec "$DEST" "$ARGS" 30 | fi 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Various. 2 | 3 | Note that files in the repository have various licenses. 4 | 5 | Some files originate from the Apple Open Source repository, and are subject to the 6 | Apple Public Open Source License Version 2.0. Other files may have other 7 | licenses as per each source file. 8 | 9 | Parts of this project that have been created by members of the MacPorts community 10 | are under the MIT License 11 | 12 | Copyright (c) 2018-2025 Chris Jones, Michael Dickens 13 | Mihai Moldovan, and many other contributing members of the MacPorts community 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /include/pthread_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_PTHREAD_IMPL_H_ 18 | #define _MACPORTS_PTHREAD_IMPL_H_ 19 | 20 | /* Include the primary system pthread_impl.h */ 21 | #include_next 22 | 23 | /* _PTHREAD_RWLOCK_SIG_init is not defined on Tiger */ 24 | #ifndef _PTHREAD_RWLOCK_SIG_init 25 | #define _PTHREAD_RWLOCK_SIG_init 0x2DA8B3B4 26 | #endif 27 | 28 | #endif /* _MACPORTS_PTHREAD_IMPL_H_ */ 29 | -------------------------------------------------------------------------------- /include/sys/attr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_ATTR_H_ 18 | #define _MACPORTS_SYS_ATTR_H_ 19 | 20 | /* Simple wrapper to add VOL_CAP_INT_CLONE (from 10.12+) */ 21 | 22 | /* Include the primary system sys/attr.h */ 23 | #include_next 24 | 25 | #ifndef VOL_CAP_INT_CLONE 26 | #define VOL_CAP_INT_CLONE 0x00010000 27 | #endif 28 | 29 | #endif /* _MACPORTS_SYS_ATTR_H_ */ 30 | -------------------------------------------------------------------------------- /test/test_sincos.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2019 Chris Jones 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | int main() { 22 | 23 | float xf, sf, cf; 24 | xf = 0.9f; 25 | __sincosf( xf, &sf, &cf ); 26 | printf( "__sincosf(%f) = %f %f\n", xf, sf, cf ); 27 | 28 | double xd, sd, cd; 29 | xd = 0.9; 30 | __sincos( xd, &sd, &cd ); 31 | printf( "__sincos(%f) = %f %f\n", xd, sd, cd ); 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/pthread_setname_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | Until such time as this behavior can be emulated, do nothing and return success. 3 | * This is what the MacPorts SpiderMonkey does: 4 | https://github.com/macports/macports-ports/commit/50cdf084768436a421e2c6d05e995d122bc93bca 5 | * This is what the MacPorts LLVM does: 6 | https://github.com/macports/macports-ports/blob/master/lang/llvm-14/files/0007-Threading-Only-call-pthread_setname_np-if-we-have-it.patch 7 | * This is what upstream dav1d does: 8 | https://code.videolan.org/videolan/dav1d/-/blob/87f9a81cd770e49394a45deca7a3df41243de00b/src/thread.h#L182 9 | vs 10 | https://code.videolan.org/videolan/dav1d/-/blob/87f9a81cd770e49394a45deca7a3df41243de00b/src/thread.h#L182 11 | * This is what upstream Rust does: 12 | https://github.com/rust-lang/rust/blob/100f12d17026fccfc5d80527b5976dd66b228b13/library/std/src/sys/unix/thread.rs#L137 13 | vs 14 | https://github.com/rust-lang/rust/blob/100f12d17026fccfc5d80527b5976dd66b228b13/library/std/src/sys/unix/thread.rs#L199 15 | */ 16 | 17 | /* MP support header */ 18 | #include "MacportsLegacySupport.h" 19 | 20 | #if __MPLS_LIB_SUPPORT_PTHREAD_SETNAME_NP__ 21 | 22 | int pthread_setname_np(const char *name) { 23 | return 0; 24 | } 25 | 26 | #endif /* __MPLS_LIB_SUPPORT_PTHREAD_SETNAME_NP__ */ 27 | -------------------------------------------------------------------------------- /include/sys/mman.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2018 Chris Jones 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MACPORTS_MMAN_H_ 19 | #define _MACPORTS_MMAN_H_ 20 | 21 | /* MP support header */ 22 | #include "MacportsLegacySupport.h" 23 | 24 | /* Include the primary system sys/mman.h */ 25 | #include_next 26 | 27 | /* MAP_ANONYMOUS only exists on 10.11+ */ 28 | /* Prior to that it was called MAP_ANON */ 29 | #ifndef MAP_ANONYMOUS 30 | #define MAP_ANONYMOUS MAP_ANON 31 | #endif 32 | 33 | #endif /* _MACPORTS_MMAN_H_ */ 34 | -------------------------------------------------------------------------------- /src/wcpcpy_family.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Christian Cornelssen 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | // MP support header 18 | #include "MacportsLegacySupport.h" 19 | 20 | #if __MPLS_LIB_SUPPORT_WCPCPY__ 21 | 22 | #include 23 | 24 | wchar_t *wcpncpy(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n) 25 | { 26 | wint_t c; 27 | while (n && (c = *s)) --n, *d++ = c, ++s; 28 | return wmemset(d, 0, n); 29 | } 30 | 31 | wchar_t *wcpcpy(wchar_t *__restrict d, const wchar_t *__restrict s) 32 | { 33 | while ((*d = *s)) ++d, ++s; 34 | return d; 35 | } 36 | 37 | #endif /* __MPLS_LIB_SUPPORT_WCPCPY__ */ 38 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_TIME_H_ 18 | #define _MACPORTS_SYS_TIME_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system sys/time.h */ 27 | #include_next 28 | 29 | #if __MPLS_SDK_SUPPORT_LUTIMES__ 30 | 31 | __MP__BEGIN_DECLS 32 | 33 | extern int lutimes(const char *, const struct timeval *); 34 | 35 | __MP__END_DECLS 36 | 37 | #endif /* __MPLS_SDK_SUPPORT_LUTIMES__ */ 38 | 39 | #endif /* _MACPORTS_SYS_TIME_H_ */ 40 | -------------------------------------------------------------------------------- /include/uuid/uuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_UUID_UUID_H_ 18 | #define _MACPORTS_UUID_UUID_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system uuid/uuid.h */ 27 | #include_next 28 | 29 | #if __MPLS_SDK_SUPPORT_UUID__ 30 | 31 | #ifndef _UUID_STRING_T 32 | #define _UUID_STRING_T 33 | typedef char uuid_string_t[37]; 34 | #endif /* _UUID_STRING_T */ 35 | 36 | #endif /* __MPLS_SDK_SUPPORT_UUID__ */ 37 | 38 | #endif /* _MACPORTS_UUID_UUID_H_ */ 39 | -------------------------------------------------------------------------------- /include/net/if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_NETIF_H_ 18 | #define _MACPORTS_NETIF_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* 27 | * This header is automatically included by on systems 10.9 and up. 28 | * It is therefore expected to be included by most current software. 29 | */ 30 | #if __MPLS_SDK_NETIF_SOCKET_FIX__ 31 | # include 32 | #endif /* __MPLS_SDK_NETIF_SOCKET_FIX__ */ 33 | 34 | /* Include the primary system */ 35 | #include_next 36 | 37 | #endif /* _MACPORTS_NETIF_H_ */ 38 | -------------------------------------------------------------------------------- /include/sys/spawn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_SPAWN_H_ 18 | #define _MACPORTS_SYS_SPAWN_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* spawn.h exists on Leopard or later. Use this block method at present 24 | * because gcc versions < 5 don't recognize __have_include() 25 | */ 26 | #if __MPLS_TARGET_OSVER >= 1050 27 | 28 | /* Include the primary system sys/spawn.h */ 29 | #include_next 30 | 31 | /* replace if missing */ 32 | #ifndef POSIX_SPAWN_CLOEXEC_DEFAULT 33 | #define POSIX_SPAWN_CLOEXEC_DEFAULT 0x4000 34 | #endif 35 | 36 | #endif /* __MPLS_TARGET_OSVER >= 1050 */ 37 | 38 | #endif /* _MACPORTS_SYS_SPAWN_H_ */ 39 | -------------------------------------------------------------------------------- /xtest/test_allheaders.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This is a test which includes all wrapper headers that we provide, in 19 | * order to verify that they can be compiled with a variety of compiler 20 | * versions, compiler options, and feature flags. The runtime "test" 21 | * is just a dummy. 22 | */ 23 | 24 | #define __MPLS_HEADER_TEST__ 25 | 26 | #include "allheaders.h" 27 | 28 | /* Explicitly include the headers we actually use here */ 29 | #include 30 | #include 31 | 32 | int 33 | main(int argc, char *argv[]) 34 | { 35 | (void) argc; (void) argv; 36 | 37 | printf("%s succeeded.\n", basename(argv[0])); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /xtest/test_revheaders.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This is a test which includes all wrapper headers that we provide, in 19 | * order to verify that they can be compiled with a variety of compiler 20 | * versions, compiler options, and feature flags. The runtime "test" 21 | * is just a dummy. 22 | */ 23 | 24 | #define __MPLS_HEADER_TEST__ 25 | 26 | #include "revheaders.h" 27 | 28 | /* Explicitly include the headers we actually use here */ 29 | #include 30 | #include 31 | 32 | int 33 | main(int argc, char *argv[]) 34 | { 35 | (void) argc; (void) argv; 36 | 37 | printf("%s succeeded.\n", basename(argv[0])); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /xtest/test_usb.c: -------------------------------------------------------------------------------- 1 | /* Test that USB.h can be successfully included */ 2 | 3 | /* 4 | * Extra hacks to allow testing with "reverse mismatched" SDK. 5 | * 6 | * Building for 10.15 with a <10.12 SDK fails due to referencing a 7 | * missing definition for uuid_t. This situation is extremely unlikely 8 | * to occur "for real", so we only fix it in the test, just so that we don't 9 | * need to exclude this test from the allowable "reverse mismatch" tests. 10 | * 11 | * Similarly, we provide a missing (empty) definition for building 12 | * 26.x+ with a <12.x SDK. 13 | */ 14 | 15 | #if defined(_MACPORTS_LEGACY_MIN_EARLY_SDK_ALLOWED) \ 16 | && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) 17 | 18 | #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 \ 19 | && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000 20 | 21 | #include <_macports_extras/sdkversion.h> 22 | 23 | #if __MPLS_SDK_MAJOR < 101200 24 | 25 | #include 26 | typedef __darwin_uuid_t uuid_t; 27 | 28 | #endif /* __MPLS_SDK_MAJOR < 101200 */ 29 | 30 | #endif /* 10.15 target */ 31 | 32 | #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 260000 33 | 34 | #ifndef __kernel_ptr_semantics 35 | #define __kernel_ptr_semantics 36 | #endif 37 | 38 | #endif /* 26.x+ target */ 39 | 40 | #endif /* Older SDK allowed and known target */ 41 | 42 | #include 43 | #include 44 | 45 | int main() { 46 | printf("Including succeeded\n"); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /xtest/test_utunh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This test is just a minimal test to verify the include of net/if_utun.h. 19 | * 20 | * It's a poorly written header that fails to include other headers that 21 | * it needs, so we have to add them. This has nothing to do with the 22 | * pre-10.6 issue. 23 | */ 24 | 25 | #include 26 | 27 | #include /* For struct sockaddr_storage in 10.8 */ 28 | #include /* For u_int64_t */ 29 | 30 | #include 31 | 32 | int 33 | main(int argc, char *argv[]) 34 | { 35 | (void) argc; (void) argv; 36 | 37 | printf("net/if_utun.h successfully included\n"); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /include/CoreFoundation/CoreFoundation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_CoreFoundation_CoreFoundation_H_ 18 | #define _MACPORTS_CoreFoundation_CoreFoundation_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system CoreFoundation/CoreFoundation.h */ 27 | #include_next 28 | 29 | #if __MPLS_SDK_SUPPORT_CoreFoundation__ 30 | 31 | #define CFPropertyListCreateWithStream(A,B,C,D,E,F) CFPropertyListCreateFromStream(A,B,C,D,E,F) 32 | 33 | #endif /* __MPLS_SDK_SUPPORT_CoreFoundation__ */ 34 | 35 | #endif /* _MACPORTS_CoreFoundation_CoreFoundation_H_ */ 36 | -------------------------------------------------------------------------------- /src/dirfuncs_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* Prototypes for directory function compatibility wrappers */ 18 | 19 | #ifndef __MACPORTS_DIRFUNCS_COMPAT_H 20 | #define __MACPORTS_DIRFUNCS_COMPAT_H 21 | 22 | #include 23 | 24 | DIR * 25 | __mpls_opendir(const char *filename); 26 | 27 | struct dirent * 28 | __mpls_readdir(DIR *dirp); 29 | 30 | int 31 | __mpls_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); 32 | 33 | long 34 | __mpls_telldir(DIR *dirp); 35 | 36 | void 37 | __mpls_seekdir(DIR *dirp, long loc); 38 | 39 | void 40 | __mpls_rewinddir(DIR *dirp); 41 | 42 | int 43 | __mpls_closedir(DIR *dirp); 44 | 45 | int 46 | __mpls_dirfd(DIR *dirp); 47 | 48 | #endif /* __MACPORTS_DIRFUNCS_COMPAT_H */ 49 | -------------------------------------------------------------------------------- /include/IOKit/usb/USB.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Evan Miller 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* pack(1) and align=reset don't mix in some versions of GCC. 18 | * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909 */ 19 | #if defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__clang__) 20 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 21 | /* 10.4 and up need three invocations */ 22 | #pragma options align=power 23 | #pragma options align=power 24 | #pragma options align=power 25 | /* 10.8 and up need two more */ 26 | #pragma options align=power 27 | #pragma options align=power 28 | /* 10.15 and up need none (extras won't hurt so SDK branching is unimplemented) */ 29 | #endif 30 | #endif 31 | 32 | /* Include the primary system IOKit/usb/USB.h */ 33 | #include_next 34 | -------------------------------------------------------------------------------- /src/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __MACPORTS_COMPILER_H 18 | #define __MACPORTS_COMPILER_H 19 | 20 | /* Macros for compiler-specific features */ 21 | 22 | /* Branch prediction hints, similar to Apple's os_fastpath/os_slowpath */ 23 | #ifdef __has_builtin 24 | #if __has_builtin(__builtin_expect) 25 | #define MPLS_EXPECT(x, v) __builtin_expect((x), (v)) 26 | #define MPLS_FASTPATH(x) ((__typeof__(x))MPLS_EXPECT((long)(x), ~0l)) 27 | #define MPLS_SLOWPATH(x) ((__typeof__(x))MPLS_EXPECT((long)(x), 0l)) 28 | #endif 29 | #endif /* __has_builtin */ 30 | 31 | #ifndef MPLS_EXPECT 32 | #define MPLS_EXPECT(x, v) (x) 33 | #define MPLS_FASTPATH(x) (x) 34 | #define MPLS_SLOWPATH(x) (x) 35 | #endif 36 | 37 | #endif /* __MACPORTS_COMPILER_H */ 38 | -------------------------------------------------------------------------------- /include/mach/mach_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_MACH_TIME_H_ 18 | #define _MACPORTS_MACH_TIME_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system mach/mach_time.h */ 27 | #include_next 28 | 29 | __MP__BEGIN_DECLS 30 | 31 | #if __MPLS_SDK_SUPPORT_APPROX_TIME__ 32 | 33 | uint64_t mach_approximate_time(void); 34 | 35 | #endif /* __MPLS_SDK_SUPPORT_APPROX_TIME__ */ 36 | 37 | #if __MPLS_SDK_SUPPORT_CONTINUOUS_TIME__ 38 | 39 | uint64_t mach_continuous_time(void); 40 | uint64_t mach_continuous_approximate_time(void); 41 | 42 | #endif /* __MPLS_SDK_SUPPORT_CONTINUOUS_TIME__ */ 43 | 44 | __MP__END_DECLS 45 | 46 | #endif /* _MACPORTS_MACH_TIME_H_ */ 47 | -------------------------------------------------------------------------------- /include/available.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This header exists solely in the 10.5 SDK, and is approximately equivalent 19 | * to AvailabilityMacros.h, except for the leading underscores in its macros. 20 | * It doesn't play nicely with our "older SDK" hack in sdkversions.h, so 21 | * we tweak it a bit here. 22 | */ 23 | 24 | /* Do our SDK-related setup */ 25 | #include <_macports_extras/sdkversion.h> 26 | 27 | /* Now fix up the values we fudged */ 28 | 29 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 30 | #undef __MAC_OS_X_VERSION_MIN_REQUIRED 31 | #define __MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_MIN_REQUIRED 32 | #endif 33 | 34 | #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED 35 | #undef __MAC_OS_X_VERSION_MAX_ALLOWED 36 | #define __MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_MAX_ALLOWED 37 | #endif 38 | 39 | #include_next 40 | -------------------------------------------------------------------------------- /test/test_renameat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * Currently this is just an "almost dummy" test, just to verify that 19 | * renameat() is declared in the expected header and defined in the 20 | * library (if needed). 21 | * 22 | * The declaration of renameat() is actually in sys/stdio.h, but that's 23 | * included by stdio.h, so we test it there. 24 | */ 25 | 26 | #include 27 | 28 | /* 29 | * This is *not* static, to keep it from being optimized out, and thereby 30 | * forcing a reference to the library or system renameat(). 31 | */ 32 | int 33 | our_renameat(int olddirfd, const char *oldpath, 34 | int newdirfd, const char *newpath) 35 | { 36 | return renameat(olddirfd, oldpath, newdirfd, newpath); 37 | } 38 | 39 | int 40 | main(int argc, char *argv[]) 41 | { 42 | (void) argc; (void) argv; 43 | 44 | (void) our_renameat; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /include/sys/fsgetpath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_FSGETPATH_H_ 18 | #define _MACPORTS_SYS_FSGETPATH_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system sys/fsgetpath.h (10.13+ only) */ 27 | #if __MPLS_SDK_MAJOR >= 101300 28 | #include_next 29 | #endif 30 | 31 | #if __MPLS_SDK_SUPPORT_FSGETPATH__ 32 | 33 | __MP__BEGIN_DECLS 34 | typedef struct fsid fsid_t; 35 | extern ssize_t fsgetpath(char * __restrict buf, size_t bufsize, fsid_t* fsid, uint64_t objid); 36 | __MP__END_DECLS 37 | 38 | #if __MPLS_TARGET_OSVER < 1060 && !defined(__MPLS_HEADER_TEST__) 39 | #error "No implementation of fsgetpath is presently available for MacOSX prior to 10.6" 40 | #endif 41 | 42 | #endif /* __MPLS_SDK_SUPPORT_FSGETPATH__ */ 43 | 44 | #endif /* _MACPORTS_SYS_FSGETPATH_H_ */ 45 | -------------------------------------------------------------------------------- /xtest/test_dirent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * An earlier implementation of fdopendir() defined seekdir as a macro, 19 | * which originally conflicted with a C++ library definition. It was fixed 20 | * to avoid that, and the test that this replaces was written in C++ in 21 | * order to verify the fix. But C++ tests have become more problematic 22 | * as of the 15.x SDK, and meanwhile, the fdopendir() implementation was 23 | * rewritten to use a different approach, making the old test moot. 24 | * 25 | * This test is now just a dummy to verify the include of dirent.h. 26 | * The original C++ test still exists, but now as: 27 | * manual_tests/dirent_with_cplusplus.cpp 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | int 34 | main(int argc, char *argv[]) 35 | { 36 | (void) argc; (void) argv; 37 | 38 | printf("dirent.h successfully included\n"); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/README-CPP.txt: -------------------------------------------------------------------------------- 1 | All functions provided by legacy-support are C functions. Use of them from C++ 2 | is via the C linkage. Thus, not only is the entire library written in plain C, 3 | but there is also no need for any tests to be written in C++. 4 | 5 | In addition, Apple made the C++ compiler requirements stricter in the macOS 15 6 | SDK, which would have been the limiting factor in compatibility with any 7 | automatic tests written in C++. Consequently, the three former C++ tests have 8 | been replaced by C versions, with the old C++ versions being moved to the manual 9 | test category. 10 | 11 | The three affected tests are: 12 | 13 | os_unfair_lock: 14 | 15 | This had a comment indicating that it needed to be in C++, with a commit 16 | reference supposedly explaining that, but neither that commit nor the ticket 17 | that it references contains any such explanation. 18 | 19 | dirent_with_cplusplus: 20 | 21 | The former fdopendir() implementation relied on a macro that collided with C++ 22 | headers, causing errors. The test was created to demonstrate that problem and 23 | its fix. It was written in C++ since that was how the problem was actually 24 | discovered, though a test using plain C probably could have been constructed. 25 | Meanwhile, the fdopendir() implementation has been rewritten in such a way that 26 | the aforementioned problem no longer exists. For that reason, the test was 27 | replaced with a simple include-only test, rather than rewriting the former test 28 | in C. 29 | 30 | time_cpp: 31 | 32 | This is a test of clock_gettime() and clock_getres(), which was written in C++ 33 | for no good reason at all. It has been rewritten in C, with some additional 34 | improvements, including the ability to detect a previously undiscovered bug. 35 | -------------------------------------------------------------------------------- /include/OpenGL/gliDispatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | 18 | /* in SDKs > 10.6 this Apple header does not include glext.h. 19 | * Including it causes redefinition errors that are hard to 20 | * overcome in ports, eg mesa, so we block the loading of 21 | * glext.h here on older systems for consistent behaviour with newer systems 22 | * 23 | * Note: this header has no specific blocker as it may be called 24 | * multiple times and should have the same effect each time 25 | */ 26 | 27 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 28 | # ifdef __glext_h_ 29 | # define MACPORTS_LEGACY_SAVED_GLEXT_SET 30 | # else 31 | # define __glext_h_ 32 | # endif 33 | #endif 34 | 35 | /* Include the primary system OpenGL/gliDispatch.h */ 36 | #include_next 37 | 38 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 39 | # ifdef MACPORTS_LEGACY_SAVED_GLEXT_SET 40 | # undef MACPORTS_LEGACY_SAVED_GLEXT_SET 41 | # else 42 | # undef __glext_h_ 43 | # endif 44 | #endif 45 | -------------------------------------------------------------------------------- /xtest/test_cputypes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This test is just a minimal test to verify the added CPU_* definitions 19 | * in mach/machine.h. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #define PRINT_VAR(x) if (verbose) printf("%s = %d\n", #x, x); 29 | #define PRINT_UNDEF(x) printf(#x " is undefined\n"); ret = 1; 30 | 31 | int 32 | main(int argc, char *argv[]) 33 | { 34 | int ret = 0, verbose = 0; 35 | 36 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 37 | 38 | #ifdef CPU_TYPE_ARM 39 | PRINT_VAR(CPU_TYPE_ARM); 40 | #else 41 | PRINT_UNDEF(CPU_TYPE_ARM); 42 | #endif 43 | 44 | #ifdef CPU_SUBTYPE_ARM64E 45 | PRINT_VAR(CPU_SUBTYPE_ARM64E); 46 | #else 47 | PRINT_UNDEF(CPU_SUBTYPE_ARM64E); 48 | #endif 49 | 50 | printf("%s %s.\n", basename(argv[0]), ret ? "failed" : "passed"); 51 | return ret; 52 | } 53 | -------------------------------------------------------------------------------- /include/net/if_utun.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This is a wrapper header for net/if_utun.h, to handle its absence in 19 | * the <10.6 SDKs. In those cases, we provide a substitute; otherwise we 20 | * just pass through the SDK header. 21 | * 22 | * This makes no representation as to whether the features referenced by 23 | * the definitions in this header actually work in <10.6. 24 | * 25 | * We don't bother with a guard macro, since all we do here is include 26 | * other headers which have their own guard macros, and we don't define 27 | * anything here. 28 | */ 29 | 30 | /* Do our SDK-related setup */ 31 | #include <_macports_extras/sdkversion.h> 32 | 33 | #if __MPLS_SDK_MAJOR < 1060 34 | 35 | typedef unsigned long long u_int64_t; /* From /types.h */ 36 | #include <_macports_extras/tiger_leopard/net/if_utun.h> 37 | 38 | #else /* >= 10.6 */ 39 | 40 | #include_next 41 | 42 | #endif /* >= 10.6 */ 43 | -------------------------------------------------------------------------------- /include/secure/_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * Support for security wrappers is absent in 10.4. It's also not enabled 19 | * in the 10.4 SDK, but building for 10.4 with a later SDK and explicit 20 | * enabling results in build failures. So we undefine the enable on 10.4. 21 | * 22 | * Note that this is more aggressive than the setup in _types.h in the 10.6+ 23 | * SDK, which only *defaults* it off on 10.4. But that results in build 24 | * failures when _FORTIFY_SOURCE is set nonzero explicitly. 25 | */ 26 | #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) \ 27 | || __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 28 | #undef _FORTIFY_SOURCE 29 | #endif 30 | 31 | /* 32 | * Include the primary system secure/_common.h 33 | * 34 | * That header is nonexistent in the 10.4 SDK, but so are refernces to it, 35 | * so if we're building with a 10.4 SDK we won't be here. 36 | */ 37 | #include_next 38 | -------------------------------------------------------------------------------- /test/test_realpath_nonext.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Version of test_realpath with Darwin extensions disabled. 3 | */ 4 | 5 | /* 6 | * NOTE: This version of realpath() is completely broken on 10.15. 7 | * This is not the fault of legacy-support, since we don't currently modify 8 | * the OS realpath() behavior on 10.6+. Unless and until we provide a fix 9 | * for that OS bug, we need to carve out an exemption in this test for 10.15, 10 | * to avoid an undeserved test failure. 11 | * 12 | * It's also been discovered that it's a bit flaky on 11.x, at least on arm64 13 | * machines, including when running x86_64 under Rosetta 2. So we exempt that 14 | * as well. 15 | * 16 | * For simplicity, the OS version test is based on the build-target version 17 | * rather than checking the actual version at runtime. This means that 18 | * running this test on a different OS version than the one it was built 19 | * for may not have the desired result. 20 | */ 21 | 22 | #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) 23 | #define TARGET_OS __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 24 | #else 25 | #define TARGET_OS 1040 26 | #endif 27 | 28 | #if TARGET_OS >= 101500 && TARGET_OS < 120000 29 | 30 | #if TARGET_OS < 110000 31 | #define VERSION "10.15" 32 | #define SYMPTOM "brokenness" 33 | #else 34 | #define VERSION "11" 35 | #define SYMPTOM "flakiness" 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | int 42 | main(int argc, char *argv[]) 43 | { 44 | (void) argc; 45 | printf("%s is being skipped on macOS " VERSION " due to OS " SYMPTOM ".\n", 46 | basename(argv[0])); 47 | return 0; 48 | } 49 | 50 | #else /* Not 10.15 or 11.x */ 51 | 52 | #define _POSIX_C_SOURCE 200112L 53 | 54 | #include "test_realpath.c" 55 | 56 | #endif /* Not 10.15 or 11.x */ 57 | -------------------------------------------------------------------------------- /include/libkern/OSAtomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_OSATOMIC_H_ 18 | #define _MACPORTS_OSATOMIC_H_ 19 | 20 | /* 21 | * This is a wrapper to allow building OSAtomic.h in C89 mode. The only issue 22 | * is the lack of 'inline'. The SDK version switched to '__inline' as of 23 | * the 10.6 SDK. We mimic that with a temporary macro definition. 24 | */ 25 | 26 | #if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) \ 27 | && !defined(inline) 28 | 29 | /* Do our SDK-related setup */ 30 | #include <_macports_extras/sdkversion.h> 31 | 32 | #if __MPLS_SDK_MAJOR < 1060 33 | 34 | #define inline __inline 35 | #define __MPLS_TEMP_INLINE 36 | 37 | #endif /* Not <10.6 */ 38 | 39 | #endif /* Not < C99 */ 40 | 41 | /* Include the primary system libkern/OSAtomic.h */ 42 | #include_next 43 | 44 | #ifdef __MPLS_TEMP_INLINE 45 | #undef inline 46 | #undef __MPLS_TEMP_INLINE 47 | #endif 48 | 49 | #endif /* _MACPORTS_OSATOMIC_H_ */ 50 | -------------------------------------------------------------------------------- /test/test_os_unfair_lock.c: -------------------------------------------------------------------------------- 1 | /* Test os_unfair_lock */ 2 | 3 | /* 4 | * This test was orginally in C++, with the following useless comment: 5 | * 6 | * // see https://github.com/macports/macports-legacy-support/commit/c39f56bd335ac0f8692a5c67a9e5f0630dbbed58#r106208628 7 | * // for reason test is in C++ 8 | * 9 | * Neither the referenced commit nor its referenced ticket offer any 10 | * explanation as to why the test needs to be in C++. Additionally, 11 | * Apple has started making C++ more problematic with mismatched SDKs, 12 | * making it undesirable to include C++ tests in the normal automatic 13 | * test suite. Hence, this test has been rewritten in C, with the original 14 | * C++ version retained as a manual test. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | int 23 | main(int argc, char *argv[]) 24 | { 25 | (void) argc; (void) argv; 26 | 27 | printf("Test of os_unfair_lock started\n"); 28 | 29 | { 30 | os_unfair_lock lock = OS_UNFAIR_LOCK_INIT; 31 | os_unfair_lock_lock(&lock); 32 | 33 | assert(!os_unfair_lock_trylock(&lock) 34 | && "should return false if the lock was already locked" ); 35 | 36 | /* critical section would be here */ 37 | 38 | os_unfair_lock_unlock(&lock); 39 | } 40 | 41 | { 42 | os_unfair_lock lock = OS_UNFAIR_LOCK_INIT; 43 | assert(os_unfair_lock_trylock(&lock) 44 | && "should return true if the lock was successfully locked"); 45 | 46 | assert(!os_unfair_lock_trylock(&lock) 47 | && "should return false if the lock was already locked" ); 48 | 49 | /* critical section would be here */ 50 | 51 | os_unfair_lock_unlock(&lock); 52 | } 53 | 54 | printf("Test of os_unfair_lock completed\n"); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /include/xlocale/_wchar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Christian Cornelssen 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_XLOCALE__WCHAR_H_ 18 | #define _MACPORTS_XLOCALE__WCHAR_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system xlocale/_wchar.h */ 27 | #include_next 28 | 29 | /* Assume that this was included by wchar.h, which included sys/cdefs.h */ 30 | 31 | /* Additional functionality provided by: 32 | * POSIX.1-2008 33 | */ 34 | #if __DARWIN_C_LEVEL >= 200809L 35 | 36 | /* wcsncasecmp_l, wcscasecmp_l */ 37 | #if __MPLS_SDK_SUPPORT_WCSCASECMP__ 38 | __MP__BEGIN_DECLS 39 | extern int wcscasecmp_l(const wchar_t *l, const wchar_t *r, locale_t locale); 40 | extern int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale); 41 | __MP__END_DECLS 42 | #endif 43 | 44 | #endif /* __DARWIN_C_LEVEL >= 200809L */ 45 | 46 | #endif /* _MACPORTS_XLOCALE__WCHAR_H_ */ 47 | -------------------------------------------------------------------------------- /src/wcsnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Adapted for MacportsLegacySupport from: 3 | * https://git.musl-libc.org/cgit/musl/tree/src/string/wcsnlen.c 4 | * License text (excerpt below): 5 | * https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT 6 | * 7 | * musl as a whole is licensed under the following standard MIT license: 8 | * 9 | * Copyright © 2005-2014 Rich Felker, et al. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | // MP support header 32 | #include "MacportsLegacySupport.h" 33 | #if __MPLS_LIB_SUPPORT_WCSNLEN__ 34 | 35 | #include 36 | 37 | size_t wcsnlen(const wchar_t *s, size_t n) 38 | { 39 | const wchar_t *z = wmemchr(s, 0, n); 40 | if (z) n = z-s; 41 | return n; 42 | } 43 | 44 | #endif /* __MPLS_LIB_SUPPORT_WCSNLEN__ */ 45 | -------------------------------------------------------------------------------- /include/pthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_PTHREAD_H_ 18 | #define _MACPORTS_PTHREAD_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system pthread.h */ 27 | #include_next 28 | 29 | /* PTHREAD_RWLOCK_INITIALIZER is not defined on Tiger */ 30 | #ifndef PTHREAD_RWLOCK_INITIALIZER 31 | #define PTHREAD_RWLOCK_INITIALIZER {_PTHREAD_RWLOCK_SIG_init, {0}} 32 | #endif 33 | 34 | __MP__BEGIN_DECLS 35 | 36 | #if __MPLS_SDK_SUPPORT_PTHREAD_SETNAME_NP__ 37 | int pthread_setname_np(const char *); 38 | #endif /* __MPLS_SDK_SUPPORT_PTHREAD_SETNAME_NP__ */ 39 | 40 | #if __MPLS_SDK_ALLOW_PTHREAD_CHDIR__ \ 41 | && defined(_MACPORTS_LEGACY_PTHREAD_CHDIR) \ 42 | && _MACPORTS_LEGACY_PTHREAD_CHDIR 43 | 44 | int pthread_chdir_np(const char* path); 45 | int pthread_fchdir_np(int fd); 46 | 47 | #endif /* __MPLS_SDK_ALLOW_PTHREAD_CHDIR__ && ... */ 48 | 49 | __MP__END_DECLS 50 | 51 | #endif /* _MACPORTS_PTHREAD_H_ */ 52 | -------------------------------------------------------------------------------- /include/sys/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Chris Jones 3 | * Copyright (c) 2018 Ken Cunningham 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MACPORTS_SYS_STDIO_H_ 19 | #define _MACPORTS_SYS_STDIO_H_ 20 | 21 | /* MP support header */ 22 | #include "MacportsLegacySupport.h" 23 | 24 | /* Do our SDK-related setup */ 25 | #include <_macports_extras/sdkversion.h> 26 | 27 | /* 28 | * Include the primary system sys/stdio.h (10.10+ only) 29 | * Otherwise include sys.cdefs.h to set up __DARWIN_C_* 30 | */ 31 | #if __MPLS_SDK_MAJOR >= 101000 32 | #include_next 33 | #else 34 | #include 35 | #endif 36 | 37 | /* Additional functionality provided by: 38 | * POSIX.1-2008 39 | */ 40 | #if __DARWIN_C_LEVEL >= 200809L 41 | 42 | #if __MPLS_SDK_SUPPORT_ATCALLS__ 43 | 44 | /* renameat */ 45 | __MP__BEGIN_DECLS 46 | extern int renameat(int olddirfd, const char *oldpath, 47 | int newdirfd, const char *newpath); 48 | __MP__END_DECLS 49 | 50 | #endif /* __MPLS_SDK_SUPPORT_ATCALLS__ */ 51 | 52 | #endif /* __DARWIN_C_LEVEL >= 200809L */ 53 | 54 | #endif /* _MACPORTS_SYS_STDIO_H_ */ 55 | -------------------------------------------------------------------------------- /src/getline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Ian F. Darwin 1986-1995. 3 | * Software written by Ian F. Darwin and others; 4 | * maintained 1995-present by Christos Zoulas and others. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice immediately at the beginning of the file, without modification, 11 | * this list of conditions, and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | /* Get size_t, FILE, ssize_t. And getline, if available. */ 30 | # include 31 | # include 32 | # include 33 | 34 | #if !defined(HAVE_DECL_GETLINE) || !HAVE_DECL_GETLINE 35 | ssize_t getline(char **dst, size_t *len, FILE *fp); 36 | #endif /* !HAVE_GETLINE */ 37 | -------------------------------------------------------------------------------- /include/sys/clonefile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_CLONEFILE_H_ 18 | #define _MACPORTS_SYS_CLONEFILE_H_ 19 | 20 | /* 21 | * This is a wrapper/replacement header for sys/clonefile.h, handling its 22 | * absence in the <10.12 SDKs. In those cases, we provide substitute 23 | * definitions; otherwise we just pass through the SDK header as is. 24 | */ 25 | 26 | /* Do our SDK-related setup */ 27 | #include <_macports_extras/sdkversion.h> 28 | 29 | #if __MPLS_SDK_SUPPORT_CLONEFILE__ 30 | 31 | /* Options for clonefile calls */ 32 | #define CLONE_NOFOLLOW 0x0001 /* Don't follow symbolic links */ 33 | 34 | #include 35 | 36 | __MP__BEGIN_DECLS 37 | 38 | int clonefileat(int, const char *, int, const char *, uint32_t); 39 | int fclonefileat(int, int, const char *, uint32_t); 40 | int clonefile(const char *, const char *, uint32_t); 41 | 42 | __MP__END_DECLS 43 | 44 | #else /* !__MPLS_SDK_SUPPORT_CLONEFILE__ */ 45 | 46 | #include_next 47 | 48 | #endif /* !__MPLS_SDK_SUPPORT_CLONEFILE__ */ 49 | 50 | #endif /* _MACPORTS_SYS_CLONEFILE_H_ */ 51 | -------------------------------------------------------------------------------- /src/strndup.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan 4 | * (Royal Institute of Technology, Stockholm, Sweden). 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of the Institute nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | 36 | #ifndef HAVE_STRNDUP 37 | #define HAVE_STRNDUP 38 | 39 | char *strndup(const char *s, size_t n); 40 | 41 | #endif /* HAVE_STRNDUP */ 42 | -------------------------------------------------------------------------------- /xtest/test_math_h.c: -------------------------------------------------------------------------------- 1 | /* Simple test to verify that math.h can be compiled. */ 2 | 3 | #include <_macports_extras/sdkversion.h> 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 10 | #define TARGET_OSVER __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 11 | #else 12 | #define TARGET_OSVER 1040 13 | #endif 14 | 15 | #if defined(__clang_major__) 16 | #define COMPILER "clang %d.%d", __clang_major__, __clang_minor__ 17 | #elif defined(__GNUC__) 18 | #define COMPILER "gcc %d.%d", __GNUC__, __GNUC_MINOR__ 19 | #else 20 | #define COMPILER "" 21 | #endif 22 | 23 | #if defined(__APPLE_CC__) 24 | #define COMPILER_APPLE " (Apple %d)\n", __APPLE_CC__ 25 | #else 26 | #define COMPILER_APPLE "\n" 27 | #endif 28 | 29 | #if defined(__x86_64__) 30 | #define ARCH "x86_64" 31 | #elif defined(__arm64__) 32 | #define ARCH "arm64" 33 | #else 34 | #define ARCH "non-_Float16" 35 | #endif 36 | 37 | static void 38 | print_basic(void) 39 | { 40 | #if __MPLS_SDK_MAJOR < 150000 41 | printf("No _Float16 workaround needed.\n"); 42 | #elif !defined(_Float16) 43 | printf("math.h builds without _Float16 workaround\n"); 44 | #else 45 | printf("math.h builds with _Float16 defined as a macro\n"); 46 | #endif 47 | } 48 | 49 | static 50 | void 51 | print_details(void) 52 | { 53 | printf("Target OS is %d\n", TARGET_OSVER); 54 | printf("SDK major version is %d\n", __MPLS_SDK_MAJOR); 55 | printf("Compiler is " COMPILER); 56 | printf(COMPILER_APPLE); 57 | printf("Architecture is " ARCH "\n"); 58 | printf("__MPLS_FLOAT16_STATUS = %d\n", __MPLS_FLOAT16_STATUS); 59 | } 60 | 61 | int 62 | main(int argc, char *argv[]) 63 | { 64 | int verbose = 0; 65 | 66 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 67 | 68 | print_basic(); 69 | 70 | if (verbose) { 71 | print_details(); 72 | printf("\n"); 73 | } 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/getdelim.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Ian F. Darwin 1986-1995. 3 | * Software written by Ian F. Darwin and others; 4 | * maintained 1995-present by Christos Zoulas and others. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice immediately at the beginning of the file, without modification, 11 | * this list of conditions, and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | /* Get size_t, FILE, ssize_t. And getdelim, if available. */ 30 | # include 31 | # include 32 | # include 33 | 34 | #if !defined(HAVE_DECL_GETDELIM) || !HAVE_DECL_GETDELIM 35 | ssize_t getdelim(char **dst, size_t *len, int delimiter, FILE *fp); 36 | #endif /* !HAVE_GETDELIM */ 37 | -------------------------------------------------------------------------------- /src/endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef __MACPORTS_ENDIAN_H 18 | #define __MACPORTS_ENDIAN_H 19 | 20 | #include 21 | 22 | /* 23 | * Macros for byte-swapping by operand size 24 | * 25 | * Although these use switch() statements, the switch() arg is a compile-time 26 | * constant, so the optimizer will normally reduce them to single cases. 27 | */ 28 | 29 | /* Common internal part */ 30 | #define __BYTE_SWAP_INTERNAL(dst,src,sizarg) \ 31 | switch (sizeof(sizarg)) { \ 32 | case 2: dst = OSSwapInt16(src); break; \ 33 | case 4: dst = OSSwapInt32(src); break; \ 34 | case 8: dst = OSSwapInt64(src); break; \ 35 | } 36 | 37 | /* In-place swap */ 38 | #define BYTE_SWAP_INPLACE(loc) __BYTE_SWAP_INTERNAL(loc,loc,loc) 39 | 40 | /* Copy swapped by size of source */ 41 | #define BYTE_SWAP_BY_SOURCE(dst,src) __BYTE_SWAP_INTERNAL(dst,src,src) 42 | 43 | /* Copy swapped by size of destination (source converted before swapping) */ 44 | #define BYTE_SWAP_BY_DEST(dst,src) \ 45 | __BYTE_SWAP_INTERNAL(dst,(__typeof__(dst))(src),dst) 46 | 47 | #endif /* __MACPORTS_ENDIAN_H */ 48 | -------------------------------------------------------------------------------- /src/wcsdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Tim J. Robbins. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | */ 26 | 27 | // MP support header 28 | #include "MacportsLegacySupport.h" 29 | #if __MPLS_LIB_SUPPORT_WCSDUP__ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | wchar_t * 36 | wcsdup(const wchar_t *s) 37 | { 38 | wchar_t *copy; 39 | size_t len; 40 | 41 | len = wcslen(s) + 1; 42 | if ((copy = malloc(len * sizeof(wchar_t))) == NULL) 43 | return (NULL); 44 | return (wmemcpy(copy, s, len)); 45 | } 46 | 47 | #endif /* __MPLS_LIB_SUPPORT_WCSDUP__ */ 48 | -------------------------------------------------------------------------------- /src/getline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 The NetBSD Foundation, Inc. 3 | * All rights reserved. 4 | * 5 | * This code is derived from software contributed to The NetBSD Foundation 6 | * by Christos Zoulas. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | // MP support header 31 | #include "MacportsLegacySupport.h" 32 | #if __MPLS_LIB_SUPPORT_GETLINE__ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | #include 36 | #endif 37 | 38 | #include "getdelim.h" 39 | #include "getline.h" 40 | 41 | ssize_t 42 | getline(char **buf, size_t *bufsiz, FILE *fp) 43 | { 44 | return getdelim(buf, bufsiz, '\n', fp); 45 | } 46 | 47 | #endif /* __MPLS_LIB_SUPPORT_GETLINE__ */ 48 | -------------------------------------------------------------------------------- /test/test_dirfuncs_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This leverages the existing tests for the old __mpls_* wrappers as tests 19 | * for the new transparent wrappers provided for compatibility, by defining 20 | * the relevant functions as macros and reusing all of test_fdopendir. 21 | * 22 | * For OS versions that never used the wrappers, this entire test is a dummy. 23 | * Because of that condition, this test is an exception to the rule that tests 24 | * shouldn't check the feature flags. 25 | */ 26 | 27 | /* MP support header */ 28 | #include "MacportsLegacySupport.h" 29 | #if __MPLS_LIB_SUPPORT_ATCALLS__ 30 | 31 | #include "../src/dirfuncs_compat.h" 32 | 33 | #define opendir __mpls_opendir 34 | #define readdir __mpls_readdir 35 | #define readdir_r __mpls_readdir_r 36 | #define telldir __mpls_telldir 37 | #define seekdir __mpls_seekdir 38 | #define rewinddir __mpls_rewinddir 39 | #define closedir __mpls_closedir 40 | #undef dirfd 41 | #define dirfd __mpls_dirfd 42 | 43 | #include "test_fdopendir.c" 44 | 45 | #else /* !__MPLS_LIB_SUPPORT_ATCALLS__ */ 46 | 47 | int main(){ return 0; } 48 | 49 | #endif /* !__MPLS_LIB_SUPPORT_ATCALLS__ */ 50 | -------------------------------------------------------------------------------- /include/strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Chris Jones 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_STRINGS_H_ 18 | #define _MACPORTS_STRINGS_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system strings.h */ 27 | #include_next 28 | 29 | /* Darwin extensions */ 30 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL 31 | 32 | /* ffsl */ 33 | #if __MPLS_SDK_SUPPORT_FFSL__ 34 | __MP__BEGIN_DECLS 35 | extern int ffsl(long int); 36 | __MP__END_DECLS 37 | #endif 38 | 39 | /* ffsll */ 40 | #if __MPLS_SDK_SUPPORT_FFSLL__ 41 | __MP__BEGIN_DECLS 42 | extern int ffsll(long long int); 43 | __MP__END_DECLS 44 | #endif 45 | 46 | /* fls */ 47 | #if __MPLS_SDK_SUPPORT_FLS__ 48 | __MP__BEGIN_DECLS 49 | extern int fls(int); 50 | __MP__END_DECLS 51 | #endif 52 | 53 | /* flsl */ 54 | #if __MPLS_SDK_SUPPORT_FLSL__ 55 | __MP__BEGIN_DECLS 56 | extern int flsl(long int); 57 | __MP__END_DECLS 58 | #endif 59 | 60 | /* flsll */ 61 | #if __MPLS_SDK_SUPPORT_FLSLL__ 62 | __MP__BEGIN_DECLS 63 | extern int flsll(long long int); 64 | __MP__END_DECLS 65 | #endif 66 | 67 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ 68 | 69 | #endif /* _MACPORTS_STRINGS_H_ */ 70 | -------------------------------------------------------------------------------- /test/test_pthread_rwlock_basic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 3 | * Copyright (c) 2025 Frederick H. G. Wright II 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main(int argc, char *argv[]) 25 | { 26 | int ret = 0, verbose = 0; 27 | 28 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 29 | 30 | /* 31 | * Note that this doesn't actually test anything, besides surviving 32 | * the calls. 33 | */ 34 | 35 | if (verbose) printf("Testing PTHREAD_RWLOCK_INITIALIZER\n"); 36 | pthread_rwlock_t aLock = PTHREAD_RWLOCK_INITIALIZER; 37 | pthread_rwlock_rdlock(&aLock); 38 | pthread_rwlock_unlock(&aLock); 39 | pthread_rwlock_destroy(&aLock); 40 | if (verbose) printf(" Success testing PTHREAD_RWLOCK_INITIALIZER\n"); 41 | 42 | if (verbose) printf("Testing pthread_rwlock_init\n"); 43 | pthread_rwlock_t myLock; 44 | pthread_rwlock_init(&myLock, NULL); 45 | pthread_rwlock_rdlock(&myLock); 46 | pthread_rwlock_unlock(&myLock); 47 | pthread_rwlock_destroy(&myLock); 48 | if (verbose) printf(" Success testing pthread_rwlock_init\n"); 49 | 50 | printf("%s %s.\n", basename(argv[0]), ret ? "failed" : "passed"); 51 | return ret; 52 | } 53 | -------------------------------------------------------------------------------- /src/lchmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | * NOTICE: This file was modified in November 2018 to allow 26 | * for use as a supporting file for MacPorts legacy support library. This notice 27 | * is included in support of clause 2.2 (b) of the Apple Public License, 28 | * Version 2.0. 29 | */ 30 | 31 | /* MP support header */ 32 | #include "MacportsLegacySupport.h" 33 | 34 | #if __MPLS_LIB_SUPPORT_LCHMOD__ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int 43 | lchmod(const char *path, mode_t mode) 44 | { 45 | struct stat s; 46 | struct attrlist a; 47 | int m; 48 | 49 | if(lstat(path, &s) < 0) 50 | return -1; 51 | if((s.st_mode & S_IFMT) != S_IFLNK) 52 | return chmod(path, mode); 53 | bzero(&a, sizeof(a)); 54 | a.bitmapcount = ATTR_BIT_MAP_COUNT; 55 | a.commonattr = ATTR_CMN_ACCESSMASK; 56 | m = mode; 57 | return setattrlist(path, &a, &m, sizeof(int), FSOPT_NOFOLLOW); 58 | } 59 | 60 | #endif /* __MPLS_LIB_SUPPORT_LCHMOD__ */ 61 | -------------------------------------------------------------------------------- /include/sys/aio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_AIO_H_ 18 | #define _MACPORTS_SYS_AIO_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* in the MacOSX10.4.sdk, several definitions are missing from this file that are included 27 | in later SDKs. This fix includes the headers in the order used in this file 28 | later SDKs, and adds the two missing definitions prior to calling the 29 | usual header. 30 | 31 | The alternate method here would be to copy in the header from the 32 | MacOSX10.4.sdk and patch it in place, as is done in gcc. We may do that 33 | in the end, if it turns out to be less intrusive. 34 | 35 | */ 36 | 37 | #if __MPLS_SDK_SYS_AIO_TIGER_FIX__ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #ifndef _OFF_T 44 | typedef __darwin_off_t off_t; 45 | #define _OFF_T 46 | #endif 47 | 48 | #ifndef _SSIZE_T 49 | #define _SSIZE_T 50 | typedef __darwin_ssize_t ssize_t; 51 | #endif 52 | 53 | #endif /* __MPLS_SDK_SYS_AIO_TIGER_FIX__ */ 54 | 55 | /* Include the primary system sys/aio.h */ 56 | #include_next 57 | 58 | #endif /* _MACPORTS_SYS_AIO_H_ */ 59 | -------------------------------------------------------------------------------- /tools/allheaders.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Script to generate list of #includes for all headers (with exceptions). 4 | # Requires git, and hence can't be used in a Makefile rule. 5 | # 6 | # This creates forward and reverse-ordered "kitchen sink" headers. 7 | # 8 | # Because the builds of some headers may be unexpectedly influenced by the 9 | # prior inclusion of other headers, this generates the list in both forward and 10 | # reverse order. By testing both, any given pair of headers is tested in 11 | # both orders of inclusion. More complex order sensitivities are not tested. 12 | 13 | DIR=$(dirname "$0") 14 | 15 | INCDIR="$DIR/../include" 16 | TSTDIR="../xtest" # Relative to INCDIR 17 | FWDFILE="$TSTDIR/allheaders.h" 18 | REVFILE="$TSTDIR/revheaders.h" 19 | 20 | # Headers not included: 21 | 22 | # Everything under _macports_extras, which are legacy-support private 23 | FILTERS='^_macports_extras' 24 | # AvailabilityInternal.h (the name says it) 25 | FILTERS+='|AvailabilityInternal.h' 26 | # Headers with a leading underscore, which are private to specific uses 27 | FILTERS+='|/_' 28 | # MacportsLegacySupport.h, which is our "configuration" header 29 | FILTERS+='|MacportsLegacySupport.h' 30 | # Framework headers under CoreFoundation, IOKit, and OpenGL 31 | FILTERS+='|CoreFoundation/|IOKit/|OpenGL/' 32 | # The 10.5-internal-only available.h 33 | FILTERS+='|available.h' 34 | # sys/attr.h requires other headers that it doesn't include 35 | FILTERS+='|sys/attr.h' 36 | 37 | # Headers without .h are C++-only, and not legal in basic-C builds. 38 | CPPFILTER='[.]h$' 39 | 40 | FWDLIST="" 41 | REVLIST="" 42 | 43 | cd "$INCDIR" 44 | for f in $(git ls-files | egrep -v "$FILTERS" ); do 45 | FWDLIST="$FWDLIST $f" 46 | REVLIST="$f $REVLIST" 47 | done 48 | 49 | makelist () { 50 | for f in $1; do 51 | if echo $f | grep -v "$CPPFILTER" >/dev/null; then 52 | echo "#ifdef __cplusplus" 53 | echo " #include <$f>" 54 | echo "#endif" 55 | else 56 | echo "#include <$f>" 57 | fi 58 | done 59 | } 60 | 61 | makelist "$FWDLIST" >"$FWDFILE" 62 | makelist "$REVLIST" >"$REVFILE" 63 | -------------------------------------------------------------------------------- /include/os/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_LOCK_H_ 18 | #define _MACPORTS_LOCK_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system os/lock.h (10.12+ only) */ 27 | #if __MPLS_SDK_MAJOR >= 101200 28 | #include_next 29 | #endif 30 | 31 | #if __MPLS_SDK_SUPPORT_OS_UNFAIR_LOCK__ 32 | 33 | /* 34 | os/lock.h does not exist 35 | use deprecated OSSpinLock instead 36 | 37 | see https://developer.apple.com/documentation/os/os_unfair_lock 38 | */ 39 | 40 | #include 41 | 42 | #define OS_UNFAIR_LOCK_INIT OS_SPINLOCK_INIT 43 | 44 | typedef OSSpinLock os_unfair_lock; 45 | typedef OSSpinLock *os_unfair_lock_t; 46 | 47 | __MP__BEGIN_DECLS 48 | 49 | void os_unfair_lock_lock(os_unfair_lock_t lock); 50 | 51 | bool os_unfair_lock_trylock(os_unfair_lock_t lock); 52 | 53 | void os_unfair_lock_unlock(os_unfair_lock_t lock); 54 | 55 | __MP__END_DECLS 56 | 57 | /* 58 | it is not clear how to implement these functions 59 | 60 | void os_unfair_lock_assert_owner(const os_unfair_lock *lock); 61 | void os_unfair_lock_assert_not_owner(const os_unfair_lock *lock); 62 | */ 63 | 64 | #endif /* __MPLS_SDK_SUPPORT_OS_UNFAIR_LOCK__ */ 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/clonefile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* MP support header */ 18 | #include "MacportsLegacySupport.h" 19 | 20 | #if __MPLS_LIB_SUPPORT_CLONEFILE__ 21 | 22 | /* 23 | * This provides degenerate implementations of *clonefile*() which always 24 | * fail, since the real versions only work on APFS, and no OS version that 25 | * uses this code supports APFS. 26 | * 27 | * At present, these functions always fail immediately with ENOTSUP, though 28 | * real implementations might fail in other ways when given bad arguments. 29 | */ 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | int 37 | clonefile(const char *src, const char *dst, uint32_t flags) 38 | { 39 | return clonefileat(AT_FDCWD, src, AT_FDCWD, dst, flags); 40 | } 41 | 42 | int 43 | clonefileat(int src_dirfd, const char *src, 44 | int dst_dirfd, const char *dst, uint32_t flags) 45 | { 46 | (void) src_dirfd; (void) src; (void) dst_dirfd; (void) dst; (void) flags; 47 | 48 | errno = ENOTSUP; 49 | return -1; 50 | } 51 | 52 | int 53 | fclonefileat(int srcfd, int dst_dirfd, const char *dst, uint32_t flags) 54 | { 55 | (void) srcfd; (void) dst_dirfd; (void) dst; (void) flags; 56 | 57 | errno = ENOTSUP; 58 | return -1; 59 | } 60 | 61 | #endif /* __MPLS_LIB_SUPPORT_CLONEFILE__ */ 62 | -------------------------------------------------------------------------------- /test/test_symbol_aliases.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This provides tests to verify that certain symbol aliases are present. 19 | * 20 | * Although there is probably a way to exploit weak references to defer 21 | * errors until runtime, there are some complications with that approach, 22 | * so we settle for simple external references, where failures are build 23 | * errors rather than runtime errors. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | /* Macro to avoid warnings converting pointer to ULL */ 30 | #if defined(__LP64__) && __LP64__ 31 | #define PTR2ULL(x) ((unsigned long long) (x)) 32 | #else 33 | #define PTR2ULL(x) ((unsigned long long) (unsigned int) (x)) 34 | #endif 35 | 36 | #define CHECK_SYMS \ 37 | SYM_MAC(__bzero) \ 38 | SYM_MAC(dirfd) 39 | 40 | #define SYM_MAC(name) \ 41 | extern void name(); \ 42 | void *name##_adr = &name; 43 | CHECK_SYMS 44 | #undef SYM_MAC 45 | 46 | int 47 | main(int argc, char *argv[]) 48 | { 49 | int verbose = 0; 50 | 51 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 52 | 53 | if (verbose) { 54 | #define SYM_MAC(name) \ 55 | printf(" " #name " = %llX\n", PTR2ULL(name##_adr)); 56 | CHECK_SYMS 57 | #undef SYM_MAC 58 | } 59 | 60 | printf("symbol aliases test passed.\n"); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /include/wchar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Chris Jones 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_WCHAR_H_ 18 | #define _MACPORTS_WCHAR_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system wchar.h */ 27 | #include_next 28 | 29 | /* Additional functionality provided by: 30 | * POSIX.1-2008 31 | */ 32 | #if __DARWIN_C_LEVEL >= 200809L 33 | 34 | __MP__BEGIN_DECLS 35 | 36 | /* wcsdup */ 37 | #if __MPLS_SDK_SUPPORT_WCSDUP__ 38 | extern wchar_t * wcsdup(const wchar_t *s); 39 | #endif 40 | 41 | /* wcsnlen */ 42 | #if __MPLS_SDK_SUPPORT_WCSNLEN__ 43 | extern size_t wcsnlen(const wchar_t *, size_t); 44 | #endif 45 | 46 | /* wcpcpy, wcpncpy */ 47 | #if __MPLS_SDK_SUPPORT_WCPCPY__ 48 | extern wchar_t * wcpcpy(wchar_t *__restrict d, const wchar_t *__restrict s); 49 | extern wchar_t *wcpncpy(wchar_t *__restrict d, const wchar_t *__restrict s, size_t n); 50 | #endif 51 | 52 | /* wcsncasecmp, wcscasecmp */ 53 | #if __MPLS_SDK_SUPPORT_WCSCASECMP__ 54 | extern int wcscasecmp(const wchar_t *l, const wchar_t *r); 55 | extern int wcsncasecmp(const wchar_t *l, const wchar_t *r, size_t n); 56 | #endif 57 | 58 | __MP__END_DECLS 59 | 60 | #endif /* __DARWIN_C_LEVEL >= 200809L */ 61 | 62 | #endif /* _MACPORTS_WCHAR_H_ */ 63 | -------------------------------------------------------------------------------- /src/strnlen.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan 4 | * (Royal Institute of Technology, Stockholm, Sweden). 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of the Institute nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef STRNLEN_H 36 | #define STRNLEN_H 37 | 38 | /* Get strnlen declaration, if available. */ 39 | #include 40 | 41 | /* Find the length (number of bytes) of STRING, but scan at most 42 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, 43 | return MAXLEN. */ 44 | extern size_t strnlen(const char *s, size_t len); 45 | 46 | #endif /* STRNLEN_H */ 47 | -------------------------------------------------------------------------------- /src/os_unfair_lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* MP support header */ 18 | #include "MacportsLegacySupport.h" 19 | 20 | /* Do our SDK-related setup */ 21 | #include <_macports_extras/sdkversion.h> 22 | 23 | #if __MPLS_LIB_SUPPORT_OS_UNFAIR_LOCK__ 24 | 25 | /* Allow building with later SDK. */ 26 | #if __MPLS_SDK_SUPPORT_OS_UNFAIR_LOCK__ 27 | 28 | #include 29 | 30 | #else /* !__MPLS_SDK_SUPPORT_OS_UNFAIR_LOCK__ */ 31 | 32 | #include 33 | #include 34 | 35 | typedef int32_t OSSpinLock; 36 | typedef OSSpinLock *os_unfair_lock_t; 37 | 38 | bool OSSpinLockTry( volatile OSSpinLock *__lock ); 39 | void OSSpinLockLock( volatile OSSpinLock *__lock ); 40 | void OSSpinLockUnlock( volatile OSSpinLock *__lock ); 41 | 42 | #endif /* !__MPLS_SDK_SUPPORT_OS_UNFAIR_LOCK__ */ 43 | 44 | /* 45 | * Note that, depending on the SDK used, the caller's os_unfair_lock_t might be: 46 | * 47 | * int32_t * 48 | * or: 49 | * struct {int32_t} * 50 | * 51 | * But this doesn't affect the actual code. 52 | */ 53 | 54 | void os_unfair_lock_lock(os_unfair_lock_t lock) { 55 | OSSpinLockLock(lock); 56 | } 57 | 58 | bool os_unfair_lock_trylock(os_unfair_lock_t lock) { 59 | return OSSpinLockTry(lock); 60 | } 61 | 62 | void os_unfair_lock_unlock(os_unfair_lock_t lock) { 63 | OSSpinLockUnlock(lock); 64 | } 65 | 66 | #endif /* __MPLS_LIB_SUPPORT_OS_UNFAIR_LOCK__ */ 67 | -------------------------------------------------------------------------------- /src/wcscasecmp_family.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Christian Cornelssen 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | // MP support header 18 | #include "MacportsLegacySupport.h" 19 | 20 | #if __MPLS_LIB_SUPPORT_WCSCASECMP__ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #if WCHAR_MAX > INT_MAX 29 | /* Caution: multiple argument evaluations */ 30 | #define _MP_WCDIFFSIGN(a, b) (((b) < (a)) - ((a) < (b))) 31 | #else 32 | #define _MP_WCDIFFSIGN(a, b) ((int)(a) - (int)(b)) 33 | #endif 34 | 35 | int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale) 36 | { 37 | wint_t lc, rc; 38 | int d = 0; 39 | while (!d && n) { 40 | lc = *l++; rc = *r++; --n; 41 | if (!(lc && rc)) n = 0; 42 | if (lc == rc) continue; 43 | lc = towlower_l(lc, locale); 44 | rc = towlower_l(rc, locale); 45 | d = _MP_WCDIFFSIGN(lc, rc); 46 | } 47 | return d; 48 | } 49 | 50 | int wcsncasecmp(const wchar_t *l, const wchar_t *r, size_t n) 51 | { 52 | return wcsncasecmp_l(l, r, n, 0); 53 | } 54 | 55 | int wcscasecmp_l(const wchar_t *l, const wchar_t *r, locale_t locale) 56 | { 57 | return wcsncasecmp_l(l, r, -1, locale); 58 | } 59 | 60 | int wcscasecmp(const wchar_t *l, const wchar_t *r) 61 | { 62 | return wcsncasecmp_l(l, r, -1, 0); 63 | } 64 | 65 | #endif /* __MPLS_LIB_SUPPORT_WCSCASECMP__ */ 66 | -------------------------------------------------------------------------------- /src/symbol_aliases.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* MP support header */ 18 | #include "MacportsLegacySupport.h" 19 | 20 | /* Do our SDK-related setup */ 21 | #include <_macports_extras/sdkversion.h> /* For 10.4 hack */ 22 | 23 | #if __MPLS_LIB_SUPPORT_SYMBOL____bzero__ 24 | 25 | #include 26 | /* 27 | The need for this function is highly limited. 28 | The symbol `__bzero` does not exist prior to 10.6. 29 | When the Rust stage0 compiler for 10.5 is built on newer machines, it bakes `__bzero` into librustc_driver-xxx.dylib. 30 | This may be due to the fact that on newer machines, the `_bzero` symbol is an indirect reference to another symbol. 31 | */ 32 | void __bzero(void *s, size_t n) { bzero(s, n); } 33 | #endif /* __MPLS_LIB_SUPPORT_SYMBOL____bzero__ */ 34 | 35 | #if __MPLS_LIB_SUPPORT_SYMBOL__dirfd__ 36 | #include 37 | #include 38 | #include 39 | /* 40 | The need for this function is highly limited. 41 | Prior to 10.8, `dirfd` was a macro`. 42 | The Rust compiler requires `dirfd` to be a library symbol. 43 | */ 44 | #undef dirfd 45 | #if __MPLS_SDK_MAJOR < 1050 46 | #define __dd_fd dd_fd 47 | #endif /* __MPLS_SDK_MAJOR < 1050 */ 48 | int dirfd(DIR *dirp) 49 | { 50 | if (dirp == NULL || dirp->__dd_fd < 0) 51 | { 52 | errno = EINVAL; 53 | return -1; 54 | } 55 | else 56 | return dirp->__dd_fd; 57 | } 58 | #endif /* __MPLS_LIB_SUPPORT_SYMBOL__dirfd__ */ 59 | -------------------------------------------------------------------------------- /include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Chris Jones 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_FCNTL_H_ 18 | #define _MACPORTS_SYS_FCNTL_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Include the primary system sys/fcntl.h */ 27 | #include_next 28 | 29 | /* replace missing (<10.7) O_CLOEXEC definition with 0, which works 30 | * but does not replace the full function of that flag 31 | * this is the commonly done fix in MacPorts (see gtk3, for example) 32 | * FIXME - this could use a proper fix, if possible 33 | */ 34 | 35 | #ifndef O_CLOEXEC 36 | #define O_CLOEXEC 0 37 | #endif 38 | 39 | #if __DARWIN_C_LEVEL >= 200809L 40 | 41 | /* atcalls */ 42 | #if __MPLS_SDK_SUPPORT_ATCALLS__ 43 | 44 | #define AT_FDCWD -2 /*Descriptor value for the current working directory */ 45 | #define AT_EACCESS 0x0010 /* Use effective ids in access check */ 46 | #define AT_SYMLINK_NOFOLLOW 0x0020 /* Act on the symlink itself not the target */ 47 | #define AT_SYMLINK_FOLLOW 0x0040 /* Act on target of symlink */ 48 | #define AT_REMOVEDIR 0x0080 /* Path refers to directory */ 49 | 50 | __MP__BEGIN_DECLS 51 | 52 | extern int openat(int dirfd, const char *pathname, int flags, ...); 53 | 54 | __MP__END_DECLS 55 | 56 | #endif /* __MPLS_SDK_SUPPORT_ATCALLS__ */ 57 | 58 | #endif /* __DARWIN_C_LEVEL >= 200809L */ 59 | 60 | #endif /* _MACPORTS_SYS_FCNTL_H_ */ 61 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* This (conditionally) contains miscellaneous global utility features. */ 18 | 19 | /* MP support header */ 20 | #include "MacportsLegacySupport.h" 21 | 22 | #include 23 | #include 24 | 25 | #include "compiler.h" 26 | 27 | /* Composite conditionals, determining need for functions */ 28 | 29 | #define __MPLS_NEED_CHECK_ACCESS__ \ 30 | (__MPLS_LIB_FIX_TIGER_PPC64__ \ 31 | || __MPLS_LIB_SUPPORT_STAT64__) 32 | 33 | /* 34 | * Obtain the address of an OS function, with an optional suffix 35 | * 36 | * This provides both the variable and the code to obtain a pointer to 37 | * a given OS function via dlsym(), with an optional variant-related 38 | * suffix (e.g. '$UNIX2003') to use in the lookup. 39 | * 40 | * Args are: 41 | * name: the standard function name 42 | * suffix: the optional suffix 43 | */ 44 | #define GET_OS_ALT_FUNC(name, suffix) \ 45 | static __typeof__(name) *os_##name = NULL; \ 46 | \ 47 | if (MPLS_SLOWPATH(!os_##name)) { \ 48 | if (!(os_##name = dlsym(RTLD_NEXT, #name #suffix))) abort(); \ 49 | } 50 | 51 | /* Obtain the address of an OS function, without an optional suffix */ 52 | #define GET_OS_FUNC(name) GET_OS_ALT_FUNC(name,) 53 | 54 | #if __MPLS_NEED_CHECK_ACCESS__ 55 | 56 | #include 57 | 58 | int __mpls_check_access(void *adr, mach_vm_size_t size, vm_prot_t access, 59 | void *okadr); 60 | 61 | #endif /* __MPLS_NEED_CHECK_ACCESS__ */ 62 | -------------------------------------------------------------------------------- /src/strnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan 3 | * (Royal Institute of Technology, Stockholm, Sweden). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the Institute nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | // MP support header 35 | #include "MacportsLegacySupport.h" 36 | #if __MPLS_LIB_SUPPORT_STRNLEN__ 37 | 38 | #ifdef HAVE_CONFIG_H 39 | # include 40 | #endif 41 | 42 | #include "strnlen.h" 43 | 44 | /* Find the length of STRING, but scan at most MAXLEN characters. 45 | If no '\0' terminator is found in that many characters, return MAXLEN. */ 46 | 47 | size_t 48 | strnlen (const char *s, size_t len) 49 | { 50 | size_t i; 51 | 52 | for(i = 0; i < len && s[i]; i++) 53 | ; 54 | return i; 55 | } 56 | 57 | #endif /* __MPLS_LIB_SUPPORT_STRNLEN__ */ 58 | -------------------------------------------------------------------------------- /test/test_pthread_get_stacksize_np.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | size_t stack_size_main = 0; 8 | size_t stack_size_thread = 0; 9 | size_t stack_size_detached = 0; 10 | 11 | void *thread_function(void *arg) { 12 | assert( !pthread_main_np() && "Unknown error, thread should *not* be main" ); 13 | stack_size_thread = pthread_get_stacksize_np(pthread_self()); 14 | assert( stack_size_thread && "Unknown error, stack size should *not* be zero" ); 15 | return NULL; 16 | } 17 | 18 | void *detached_function(void *arg) { 19 | assert( !pthread_main_np() && "Unknown error, thread should *not* be main" ); 20 | stack_size_detached = pthread_get_stacksize_np(pthread_self()); 21 | assert( stack_size_detached && "Unknown error, stack size should *not* be zero" ); 22 | return NULL; 23 | } 24 | 25 | int main() 26 | { 27 | pthread_t thread; 28 | pthread_t thread_detached; 29 | pthread_attr_t attr; 30 | 31 | assert( pthread_main_np() && "Unknown error, thread should be main." ); 32 | stack_size_main = pthread_get_stacksize_np(pthread_self()); 33 | 34 | assert( !pthread_create(&thread, NULL, thread_function, NULL) && "Unknown error, cannot create first thread" ); 35 | pthread_join(thread, NULL); 36 | 37 | assert( !pthread_attr_init(&attr) && "Unknown error, cannot initialises attribute" ); 38 | assert( !pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) && "Unknown error, cannot set detached state" ); 39 | assert( !pthread_create(&thread_detached, &attr, detached_function, NULL) && "Unknown error, cannot create second thread" ); 40 | assert( !pthread_attr_destroy(&attr) && "Unknown error, cannot destroy attribute" ); 41 | 42 | do { 43 | usleep(1000); 44 | } while( !stack_size_detached ); 45 | 46 | assert( stack_size_thread == stack_size_detached && "Unknown Error, non-main threads are assumed to have the same stack size" ); 47 | assert( stack_size_main > stack_size_thread && "Default stack size for main thread is the same as the default stack size of non-main threads" ); 48 | 49 | printf("Stack size for the main thread (%zu) is larger than for non-main threads (%zu), which is expected.\n", stack_size_main, stack_size_thread); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /include/AvailabilityMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * A complication here is that some recent compilers treat preprocessor 19 | * undefined warnings as errors, and 10.15+ SDKs reference the possibly 20 | * undefined TARGET_OS_* macros. To get around that, we temporarily 21 | * define TARGET_OS_OSX as 1 if necessary, and then undo that afterward. 22 | * This assumes that we're actually building for macOS, which should usually 23 | * be the case with these headers. Setting TARGET_OS_OSX avoids the check 24 | * for TARGET_OS_MACCATALYST. The only possibly unwanted effect of this 25 | * is the "#define __IPHONE_COMPAT_VERSION __IPHONE_NA", which is most 26 | * likely correct if it matters at all. 27 | * 28 | * Now that we're providing a definition for TARGET_OS_OSX in our wrapper 29 | * for TargetConditionals.h, we need to be sure that we don't undo that 30 | * action here if it was included by this header. So we include a condition 31 | * for that. 32 | * 33 | * We don't bother with a guard macro here, since repeating the extra wrapper 34 | * code is a NOP, anyway. 35 | */ 36 | 37 | /* Avoid possible error from TARGET_OS_OSX test */ 38 | #ifndef TARGET_OS_OSX 39 | #define TARGET_OS_OSX 1 40 | #define __MPLS_TARGET_OS_OSX_UNDEF 41 | #endif 42 | 43 | #include_next 44 | 45 | /* Now restore the original TARGET_OS_OSX, unless we overrode it. */ 46 | #if defined(__MPLS_TARGET_OS_OSX_UNDEF) \ 47 | && !defined(__MPLS_TARGETCONDITIONALS__) 48 | #undef TARGET_OS_OSX 49 | #endif 50 | #undef __MPLS_TARGET_OS_OSX_UNDEF 51 | -------------------------------------------------------------------------------- /src/quarantine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Building Apple's copyfile.c requires quarantine.h, which is not a published 3 | * header, and the "embedded" fallback appeared inappropriate. 4 | * 5 | * This file (except this comment block) was taken from: 6 | * https://github.com/samdmarshall/OSXPrivateSDK/blob/master/PrivateSDK10.10.sparse.sdk/usr/include/quarantine.h 7 | * 8 | * Other changes: 9 | * Removed inappropriate 'const' from _qtn_proc_to_data prototype. 10 | */ 11 | #ifndef __quarantine_h__ 12 | #define __quarantine_h__ 13 | 14 | #include 15 | 16 | typedef struct _qtn_file_s *qtn_file_t; 17 | typedef struct qtn_proc * qtn_proc_t; 18 | 19 | #define QTN_FLAG_SANDBOX 1 20 | #define QTN_FLAG_HARD 2 21 | 22 | extern qtn_proc_t _qtn_proc_alloc(); 23 | extern void _qtn_proc_set_identifier(qtn_proc_t qp, char *identifier); 24 | extern void _qtn_proc_set_flags(qtn_proc_t qp, int flags); 25 | extern void _qtn_proc_apply_to_self(qtn_proc_t qp); 26 | extern void _qtn_proc_free(qtn_proc_t qp); 27 | 28 | extern qtn_file_t _qtn_file_alloc(); 29 | extern void _qtn_file_free(qtn_file_t); 30 | 31 | extern qtn_file_t _qtn_file_clone(qtn_file_t); 32 | 33 | extern int _qtn_file_init_with_fd(qtn_file_t file, int fd); 34 | extern int _qtn_file_apply_to_fd(qtn_file_t file, int fd); 35 | 36 | extern int _qtn_file_init_with_path(qtn_file_t file, const char *path); 37 | 38 | extern int _qtn_file_init_with_data(qtn_file_t file, const void *, size_t); 39 | extern int _qtn_file_to_data(qtn_file_t file, void *, size_t*); 40 | 41 | extern int _qtn_file_apply_to_path(qtn_file_t qf, char *path); 42 | 43 | extern const char *_qtn_error(int err); 44 | 45 | extern const char *_qtn_xattr_name; 46 | 47 | extern int _qtn_proc_to_data(void * spawn_quarantine, char *qbuf,size_t *qbuf_sz); 48 | 49 | #define QTN_SERIALIZED_DATA_MAX 4096 50 | 51 | #define qtn_file_alloc _qtn_file_alloc 52 | #define qtn_file_free _qtn_file_free 53 | 54 | #define qtn_file_clone _qtn_file_clone 55 | 56 | #define qtn_file_init_with_fd _qtn_file_init_with_fd 57 | #define qtn_file_apply_to_fd _qtn_file_apply_to_fd 58 | 59 | #define qtn_file_init_with_path _qtn_file_init_with_path 60 | 61 | #define qtn_file_init_with_data _qtn_file_init_with_data 62 | #define qtn_file_to_data _qtn_file_to_data 63 | 64 | #define qtn_error _qtn_error 65 | 66 | #define qtn_xattr_name _qtn_xattr_name 67 | 68 | #define qtn_proc_to_data _qtn_proc_to_data 69 | 70 | #endif -------------------------------------------------------------------------------- /src/strndup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 - 1999 Kungliga Tekniska Högskolan 3 | * (Royal Institute of Technology, Stockholm, Sweden). 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. Neither the name of the Institute nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | # include "config.h" 36 | #endif 37 | 38 | // MP support header 39 | #include "MacportsLegacySupport.h" 40 | #if __MPLS_LIB_SUPPORT_STRNDUP__ 41 | 42 | #ifndef HAVE_STRNDUP 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include "strnlen.h" 49 | 50 | char * 51 | strndup (const char *old, size_t sz) 52 | { 53 | size_t len = strnlen (old, sz); 54 | char *t = malloc(len + 1); 55 | 56 | if (t != NULL) { 57 | memcpy (t, old, len); 58 | t[len] = '\0'; 59 | } 60 | return t; 61 | } 62 | 63 | #endif /* HAVE_STRNDUP */ 64 | 65 | #endif /* __MPLS_LIB_SUPPORT_STRNDUP__ */ 66 | -------------------------------------------------------------------------------- /include/sys/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_RANDOM_H_ 18 | #define _MACPORTS_SYS_RANDOM_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* 27 | * In the systems that need this, sys/random.h requires the u_int typedef, 28 | * which not only depends on sys/types.h, but also may be blocked by POSIX 29 | * settings. In that case, we provide our own typedef if appropriate, or 30 | * else we avoid the include_next that won't work. 31 | * 32 | * The OS versions with getentropy() don't appear to filter it based on 33 | * POSIX settings, so we do the same here. 34 | * 35 | * In the later OSes that don't need our addition, sys/random.h is completely 36 | * different and doesn't require u_int, and thus the include_next is 37 | * unconditional. 38 | */ 39 | 40 | #if __MPLS_SDK_SUPPORT_GETENTROPY__ 41 | 42 | #if !defined(_POSIX_C_SOURCE) \ 43 | || (defined(_DARWIN_C_SOURCE) && __MPLS_SDK_MAJOR >= 1050) 44 | 45 | /* Add the missing typedef (redundancy shouldn't hurt ). */ 46 | typedef unsigned int u_int; 47 | 48 | /* Include the primary system sys/random.h */ 49 | #include_next 50 | 51 | #endif /* (!_POSIX_C_SOURCE || (_DARWIN_C_SOURCE && >10.4)) */ 52 | 53 | __MP__BEGIN_DECLS 54 | extern int getentropy(void *buf, size_t buflen); 55 | __MP__END_DECLS 56 | 57 | #else /* !__MPLS_SDK_SUPPORT_GETENTROPY__ */ 58 | 59 | /* Include the primary system sys/random.h */ 60 | #include_next 61 | 62 | #endif /* !__MPLS_SDK_SUPPORT_GETENTROPY__ */ 63 | 64 | #endif /* _MACPORTS_SYS_RANDOM_H_ */ 65 | -------------------------------------------------------------------------------- /src/getentropy.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2021 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | // MP support header 19 | #include "MacportsLegacySupport.h" 20 | #if __MPLS_LIB_SUPPORT_GETENTROPY__ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | void 34 | _error(int doexit, int err, const char* fmt, ...) 35 | { 36 | va_list ap; 37 | 38 | fflush(stdout); 39 | fflush(stderr); 40 | va_start(ap, fmt); 41 | vfprintf(stderr, fmt, ap); 42 | va_end(ap); 43 | 44 | if (err > 0) 45 | fprintf(stderr, "\n %s (Errno %d)\n", strerror(err), err); 46 | 47 | if (doexit) { 48 | fflush(stderr); 49 | exit(1); 50 | } 51 | } 52 | 53 | static int 54 | _randopen(const char* name) 55 | { 56 | int fd = open(name, O_RDONLY); 57 | if (fd < 0) { 58 | _error(1, errno, "Cannot open system random number dev %s", name); 59 | } 60 | 61 | return fd; 62 | } 63 | 64 | int 65 | getentropy(void* buf, size_t n) 66 | { 67 | 68 | static int fd = -1; 69 | uint8_t* b = (uint8_t*)buf; 70 | 71 | if (fd < 0) 72 | fd = _randopen("/dev/urandom"); 73 | 74 | while (n > 0) 75 | { 76 | ssize_t m = (read)(fd, b, n); 77 | 78 | if (m < 0) { 79 | if (errno == EINTR) continue; 80 | _error(1, errno, "Fatal read error while reading rand dev"); 81 | } 82 | b += m; 83 | n -= m; 84 | } 85 | 86 | return 0; 87 | } 88 | 89 | #endif /* __MPLS_LIB_SUPPORT_GETENTROPY__ */ 90 | -------------------------------------------------------------------------------- /manual_tests/headerinfo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This is a manual "test" to report the values of a few macros related to 19 | * SDK selection. It never "fails". 20 | */ 21 | 22 | /* Do this before everything else. */ 23 | #include <_macports_extras/sdkversion.h> 24 | 25 | /* So we can delay including stdio.h */ 26 | int printf(const char *format, ...); 27 | 28 | #define PRINT_VAR(x) printf("%s = %lld\n", #x, (long long) x) 29 | #define PRINT_UNDEF(x) printf(#x " is undefined\n") 30 | 31 | void 32 | print_defs(void) 33 | { 34 | #ifdef __APPLE__ 35 | PRINT_VAR(__APPLE__); 36 | #else 37 | PRINT_UNDEF(__APPLE__); 38 | #endif 39 | #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 40 | PRINT_VAR(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__); 41 | #else 42 | PRINT_UNDEF(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__); 43 | #endif 44 | 45 | printf("\n"); 46 | 47 | #ifdef MAC_OS_X_VERSION_MIN_REQUIRED 48 | PRINT_VAR(MAC_OS_X_VERSION_MIN_REQUIRED); 49 | #else 50 | PRINT_UNDEF(MAC_OS_X_VERSION_MIN_REQUIRED); 51 | #endif 52 | #ifdef MAC_OS_X_VERSION_MAX_ALLOWED 53 | PRINT_VAR(MAC_OS_X_VERSION_MAX_ALLOWED); 54 | #else 55 | PRINT_UNDEF(MAC_OS_X_VERSION_MAX_ALLOWED); 56 | #endif 57 | #ifdef __MPLS_SDK_MAJOR 58 | PRINT_VAR(__MPLS_SDK_MAJOR); 59 | #else 60 | PRINT_UNDEF(__MPLS_SDK_MAJOR); 61 | #endif 62 | } 63 | 64 | /* Do this afterward, since it might influence the definitions. */ 65 | #include 66 | 67 | int 68 | main(int argc, char *argv[]) 69 | { 70 | (void) argc; (void) argv; 71 | 72 | printf("\n"); 73 | print_defs(); 74 | printf("\n"); 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /include/_macports_extras/tiger_leopard/net/if_utun.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | 30 | #ifndef _NET_IF_UTUN_H_ 31 | #define _NET_IF_UTUN_H_ 32 | 33 | 34 | /* 35 | * Name registered by the utun kernel control 36 | */ 37 | #define UTUN_CONTROL_NAME "com.apple.net.utun_control" 38 | 39 | /* 40 | * Socket option names to manage utun 41 | */ 42 | #define UTUN_OPT_FLAGS 1 43 | #define UTUN_OPT_IFNAME 2 44 | #define UTUN_OPT_EXT_IFDATA_STATS 3 /* get|set (type int) */ 45 | #define UTUN_OPT_INC_IFDATA_STATS_IN 4 /* set to increment stat counters (type struct utun_stats_param) */ 46 | #define UTUN_OPT_INC_IFDATA_STATS_OUT 5 /* set to increment stat counters (type struct utun_stats_param) */ 47 | 48 | /* 49 | * Flags for by UTUN_OPT_FLAGS 50 | */ 51 | #define UTUN_FLAGS_NO_OUTPUT 0x0001 52 | #define UTUN_FLAGS_NO_INPUT 0x0002 53 | 54 | /* 55 | * utun stats parameter structure 56 | */ 57 | struct utun_stats_param { 58 | u_int64_t utsp_packets; 59 | u_int64_t utsp_bytes; 60 | u_int64_t utsp_errors; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /test/test_flsl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Chris Jones 3 | * Copyright (c) 2025 Frederick H. G. Wright II 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main(int argc, char *argv[]) 25 | { 26 | int ret = 0, verbose = 0; 27 | const int offset = 4; 28 | 29 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 30 | 31 | /* FIXME: Actually check the results for correctness */ 32 | 33 | if (verbose) printf( "testing fls :-\n" ); 34 | for ( int i = 0; i <= 8*sizeof(int)-offset; i+=offset ) { 35 | const int ii = i+offset; 36 | int test = ( i>0 ? 1UL << (i-1) : 0 ); 37 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 38 | const int j = fls(test); 39 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 40 | } 41 | 42 | if (verbose) printf( "testing flsl :-\n" ); 43 | for ( int i = 0; i <= 8*sizeof(long int)-offset; i+=offset ) { 44 | const int ii = i+offset; 45 | long int test = ( i>0 ? 1UL << (i-1) : 0 ); 46 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 47 | const int j = flsl(test); 48 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 49 | } 50 | 51 | if (verbose) printf( "testing flsll :-\n" ); 52 | for ( int i = 0; i <= 8*sizeof(long long int)-offset; i+=offset ) { 53 | const int ii = i+offset; 54 | long long int test = ( i>0 ? 1UL << (i-1) : 0 ); 55 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 56 | const int j = flsll(test); 57 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 58 | } 59 | 60 | printf("%s %s.\n", basename(argv[0]), ret ? "failed" : "succeeded"); 61 | return ret; 62 | } 63 | -------------------------------------------------------------------------------- /src/lutimes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | * NOTICE: This file was modified in October 2020 to allow 26 | * for use as a supporting file for MacPorts legacy support library. This notice 27 | * is included in support of clause 2.2 (b) of the Apple Public License, 28 | * Version 2.0. 29 | */ 30 | 31 | /* MP support header */ 32 | #include "MacportsLegacySupport.h" 33 | 34 | #if __MPLS_LIB_SUPPORT_LUTIMES__ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | int 44 | lutimes(const char *path, const struct timeval *times) 45 | { 46 | struct stat s; 47 | struct attrlist a; 48 | struct { 49 | struct timespec mod; 50 | struct timespec access; 51 | } t; 52 | 53 | if(lstat(path, &s) < 0) 54 | return -1; 55 | if((s.st_mode & S_IFMT) != S_IFLNK) 56 | return utimes(path, times); 57 | bzero(&a, sizeof(a)); 58 | a.bitmapcount = ATTR_BIT_MAP_COUNT; 59 | a.commonattr = ATTR_CMN_MODTIME | ATTR_CMN_ACCTIME; 60 | if(times) { 61 | TIMEVAL_TO_TIMESPEC(×[0], &t.access); 62 | TIMEVAL_TO_TIMESPEC(×[1], &t.mod); 63 | } else { 64 | struct timeval now; 65 | 66 | if(gettimeofday(&now, NULL) < 0) 67 | return -1; 68 | TIMEVAL_TO_TIMESPEC(&now, &t.access); 69 | TIMEVAL_TO_TIMESPEC(&now, &t.mod); 70 | } 71 | return setattrlist(path, &a, &t, sizeof(t), FSOPT_NOFOLLOW); 72 | } 73 | 74 | #endif /* __MPLS_LIB_SUPPORT_LUTIMES__ */ 75 | -------------------------------------------------------------------------------- /test/test_ffsl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Chris Jones 3 | * Copyright (c) 2025 Frederick H. G. Wright II 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main(int argc, char *argv[]) 25 | { 26 | int ret = 0, verbose = 0; 27 | const int offset = 4; 28 | 29 | if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1; 30 | 31 | /* FIXME: Actually check the results for correctness */ 32 | 33 | if (verbose) printf( "testing ffsl :-\n" ); 34 | for ( int i = 0; i <= 8*sizeof(int)-offset; i+=offset ) { 35 | const int ii = i+offset; 36 | long int test = ( i>0 ? 1UL << (i-1) : 0 ); 37 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 38 | const int j = ffs(test); 39 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 40 | } 41 | 42 | if (verbose) printf( "testing ffsl :-\n" ); 43 | for ( int i = 0; i <= 8*sizeof(long int)-offset; i+=offset ) { 44 | const int ii = i+offset; 45 | long int test = ( i>0 ? 1UL << (i-1) : 0 ); 46 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 47 | const int j = ffsl(test); 48 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 49 | } 50 | 51 | if (verbose) printf( "testing ffsll :-\n" ); 52 | for ( int i = 0; i <= 8*sizeof(long long int)-offset; i+=offset ) { 53 | const int ii = i+offset; 54 | long long int test = ( i>0 ? 1UL << (i-1) : 0 ); 55 | test |= ( ii>0 ? 1UL << (ii-1) : 0 ); 56 | const int j = ffsll(test); 57 | if (verbose) printf( " Set bits %i,%i - Found bit %i\n", i, ii, j ); 58 | } 59 | 60 | printf("%s %s.\n", basename(argv[0]), ret ? "failed" : "succeeded"); 61 | return ret; 62 | } 63 | -------------------------------------------------------------------------------- /include/MacTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * Beginning with the macOS 15 SDK, this header expects the __has_include() 19 | * operator to be available. If it isn't, then this file fails to include 20 | * ConditionalMacros.h, causing errors. Since that's the only use of this 21 | * operator in this file, we just temporarily define it as an always-true 22 | * dummy, and then undo that after the include_next. 23 | * 24 | * Since sys/cdefs.h may supply an inappropriate fallback for __has_include(), 25 | * we need to use the flag set up by our version to determine the proper 26 | * behavior. 27 | * 28 | * To avoid accidentally and possibly inappropriately applying this workaround 29 | * to a future SDK, we limit it with a both-ways SDK version check. This 30 | * should be updated as needed when new SDKs are added, as has already 31 | * been done to accommodate the macOS 26 SDK. 32 | */ 33 | 34 | /* Determine the true __has_include() status (if not already done) */ 35 | #include 36 | 37 | /* Determine the SDK version */ 38 | #include <_macports_extras/sdkversion.h> 39 | 40 | /* See if __has_include() is missing or lying */ 41 | #if __MPLS_HAS_INCLUDE_STATUS <= 0 42 | 43 | #if __MPLS_SDK_MAJOR >= 150000 && __MPLS_SDK_MAJOR < 270000 44 | #undef __has_include 45 | #define __has_include(x) 1 46 | #define __MPLS_HAS_INCLUDE_CHANGED 47 | #endif 48 | 49 | #endif /* __has_include undef */ 50 | 51 | /* Include the primary system MacTypes.h (non-system in <10.8) */ 52 | #if __MPLS_SDK_MAJOR >= 1080 || !defined(__MPLS_HEADER_TEST__) 53 | #include_next 54 | #endif 55 | 56 | #ifdef __MPLS_HAS_INCLUDE_CHANGED 57 | #undef __has_include 58 | #if __MPLS_HAS_INCLUDE_STATUS == 0 59 | #define __has_include(x) 0 60 | #endif 61 | #undef __MPLS_HAS_INCLUDE_CHANGED 62 | #endif 63 | -------------------------------------------------------------------------------- /src/memmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Pascal Gloor 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote 13 | * products derived from this software without specific prior written 14 | * permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | /* MP support header */ 30 | #include "MacportsLegacySupport.h" 31 | #if __MPLS_LIB_SUPPORT_MEMMEM__ 32 | 33 | #include 34 | #include 35 | 36 | #include "strnlen.h" 37 | 38 | /* 39 | * Find the first occurrence of the byte string s in byte string l. 40 | */ 41 | 42 | void * 43 | memmem(const void *l, size_t l_len, const void *s, size_t s_len) 44 | { 45 | register char *cur, *last; 46 | const char *cl = (const char *)l; 47 | const char *cs = (const char *)s; 48 | 49 | /* we need something to compare */ 50 | if (l_len == 0 || s_len == 0) 51 | return NULL; 52 | 53 | /* "s" must be smaller or equal to "l" */ 54 | if (l_len < s_len) 55 | return NULL; 56 | 57 | /* special case where s_len == 1 */ 58 | if (s_len == 1) 59 | return memchr(l, (int)*cs, l_len); 60 | 61 | /* the last position where its possible to find "s" in "l" */ 62 | last = (char *)cl + l_len - s_len; 63 | 64 | for (cur = (char *)cl; cur <= last; cur++) 65 | if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) 66 | return cur; 67 | 68 | return NULL; 69 | } 70 | 71 | #endif /* __MPLS_LIB_SUPPORT_MEMMEM__ */ 72 | -------------------------------------------------------------------------------- /src/dirfuncs_compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * Earlier versions of legacy-support needed wrappers around several OS 19 | * calls related to directories, in order to implement fdopendir(). That 20 | * is no longer the case, but existing dependents still reference those 21 | * wrapper calls. For compatibility, we continue to provide those functions, 22 | * but just as transparent wrappers around the OS calls. 23 | * 24 | * These wrappers can eventually be removed once all dependents have been 25 | * rebuilt with the current headers. But since there would be significant 26 | * work in determining when this is the case, and since they only add 752 27 | * bytes to the library size, they should probably be left in place for a 28 | * long time. 29 | * 30 | * This is only relevant for OS versions where our fdopendir() is needed, 31 | * hence the conditional (which is the same conditional as was used for 32 | * the earlier implementations). 33 | */ 34 | 35 | /* MP support header */ 36 | #include "MacportsLegacySupport.h" 37 | #if __MPLS_LIB_SUPPORT_ATCALLS__ 38 | 39 | #include "dirfuncs_compat.h" 40 | 41 | DIR * 42 | __mpls_opendir(const char *filename) { 43 | return opendir(filename); 44 | } 45 | 46 | struct dirent * 47 | __mpls_readdir(DIR *dirp) { 48 | return readdir(dirp); 49 | } 50 | 51 | int 52 | __mpls_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { 53 | return readdir_r(dirp, entry, result); 54 | } 55 | 56 | long 57 | __mpls_telldir(DIR *dirp) { 58 | return telldir(dirp); 59 | } 60 | 61 | void 62 | __mpls_seekdir(DIR *dirp, long loc) { 63 | seekdir(dirp, loc); 64 | } 65 | 66 | void 67 | __mpls_rewinddir(DIR *dirp) { 68 | rewinddir(dirp); 69 | } 70 | 71 | int 72 | __mpls_closedir(DIR *dirp) { 73 | return closedir(dirp); 74 | } 75 | 76 | int 77 | __mpls_dirfd(DIR *dirp) { 78 | return dirfd(dirp); 79 | } 80 | 81 | #endif /* __MPLS_LIB_SUPPORT_ATCALLS__ */ 82 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Chris Jones 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_STDLIB_H_ 18 | #define _MACPORTS_STDLIB_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | /* Work around recent compilers that treat undefineds as errors. */ 27 | #if __MPLS_SDK_MAJOR >= 101200 28 | #ifndef TARGET_OS_EMBEDDED 29 | #define TARGET_OS_EMBEDDED 0 30 | #endif 31 | #ifndef TARGET_OS_IPHONE 32 | #define TARGET_OS_IPHONE 0 33 | #endif 34 | #endif 35 | 36 | /* Include the primary system stdlib.h */ 37 | #include_next 38 | 39 | /* posix_memalign */ 40 | #if __MPLS_SDK_SUPPORT_POSIX_MEMALIGN__ 41 | 42 | /* 43 | * [XSI] The ssize_t and size_t types shall be defined as described 44 | * in . 45 | */ 46 | #ifndef _SIZE_T 47 | #define _SIZE_T 48 | typedef __darwin_size_t size_t; 49 | #endif 50 | 51 | #ifndef _SSIZE_T 52 | #define _SSIZE_T 53 | typedef __darwin_ssize_t ssize_t; 54 | #endif 55 | 56 | __MP__BEGIN_DECLS 57 | extern int posix_memalign(void **memptr, size_t alignment, size_t size); 58 | __MP__END_DECLS 59 | 60 | #endif /* __MPLS_SDK_SUPPORT_POSIX_MEMALIGN__ */ 61 | 62 | /* arc4random */ 63 | #if __MPLS_SDK_SUPPORT_ARC4RANDOM__ 64 | 65 | #ifndef _SIZE_T 66 | #define _SIZE_T 67 | typedef __darwin_size_t size_t; 68 | #endif 69 | #ifndef _UINT32_T 70 | #define _UINT32_T 71 | typedef unsigned int uint32_t; 72 | #endif 73 | 74 | /* 75 | * Generate and return a uniformly random 32-bit quantity with an 76 | * upper bound of 'upper_bound' 77 | */ 78 | __MP__BEGIN_DECLS 79 | extern uint32_t arc4random_uniform( uint32_t upper_bound ); 80 | __MP__END_DECLS 81 | 82 | /* 83 | * Generate 'n' random bytes and put them in 'buf'. 84 | */ 85 | __MP__BEGIN_DECLS 86 | extern void arc4random_buf( void* buf, size_t n ); 87 | __MP__END_DECLS 88 | 89 | #endif /* __MPLS_SDK_SUPPORT_ARC4RANDOM__ */ 90 | 91 | #endif /* _MACPORTS_STDLIB_H_ */ 92 | -------------------------------------------------------------------------------- /tools/runnablearchs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Script to determine which architectures can build and run on this machine. 4 | # The list of architectures to test can be specified on the command line; 5 | # the default is to test all primary architectures. The final output is 6 | # the filtered architecture list. 7 | # 8 | # We need to verify that the program can actually run; not just that it built. 9 | # 10 | # Some gccs ignore unsupported -arch options, so we need to include a check 11 | # in the test program to verify the expected architecture. But since there's 12 | # no '__ppc7400__' preprocessor flag, we need to map 'ppc7400' to 'ppc' while 13 | # doing this. 14 | # 15 | # In addition, some MacPorts clangs segfault when given unsupported -arch 16 | # options, causing an error message from the shell rather than clang. To get 17 | # around this, we wrap the entire compiler execution in another level of 18 | # shell, so that we can suppress the error message. 19 | # 20 | # Similarly, attempting to run an executable with an unsupported architecture 21 | # sometimes produces an error message from the shell, so we also wrap this 22 | # in another shell to allow suppressing the error message. 23 | # 24 | # Furthermore, attempts to run an arm64e executable (on arm64) fail with the 25 | # very nasty signal 9, so we also need to redirect the test program's own 26 | # stderr to hide that. 27 | # 28 | # In addition, the larval support for x86_64h on 10.9 considers x86_64h code 29 | # to be runnable on all x86_64 machines, including pre-Haswell. To get around 30 | # that, in the x86_64h case, we include a use of the MOVBE instruction, which 31 | # is one of the instructions added by Haswell. Running this on a pre-Haswell 32 | # CPU fails with an illegal instruction trap. 33 | 34 | if [ "$1" != "-a" ]; then 35 | TESTARCHS="${@:-ppc ppc64 i386 x86_64 arm64}" 36 | else 37 | TESTARCHS="ppc ppc7400 ppc64 i386 x86_64 x86_64h arm arm64 arm64e" 38 | fi 39 | 40 | if [ "$CC" == "" ]; then CC=cc; fi 41 | 42 | TESTBIN="/tmp/testprog-$$" 43 | TESTSRC="${TESTBIN}.c" 44 | 45 | RUNARCHS="" 46 | for a in $TESTARCHS; do 47 | if [ "$a" == "ppc7400" ]; then 48 | archflag="ppc" 49 | else 50 | archflag="$a" 51 | fi 52 | cat >$TESTSRC </dev/null" 2>/dev/null; then 69 | if sh -c "$TESTBIN 2>/dev/null" 2>/dev/null; then 70 | RUNARCHS="$RUNARCHS $a" 71 | fi 72 | fi; 73 | done 74 | 75 | rm -f $TESTSRC $TESTBIN 76 | 77 | echo $RUNARCHS 78 | -------------------------------------------------------------------------------- /src/stpncpy_chk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | * NOTICE: This file was modified in May 2024, and again in June 2025, to allow 26 | * for use as a supporting file for MacPorts legacy support library. This 27 | * notice is included in support of clause 2.2 (b) of the Apple Public License, 28 | * Version 2.0. 29 | * 30 | * The code is almost verbatim from Apple except for: 31 | * 32 | * The correction of the return type. 33 | * 34 | * The removal of the 'restrict' qualifiers for compatibility with 35 | * pre-C99 compilers. 36 | * 37 | * The addition of the missing 'const' qualifier. 38 | * 39 | * The _FORTIFY_SOURCE definition here in lieu of providing it as a 40 | * compiler command-line flag (as the Apple build procedure does). 41 | * 42 | * Making the reference to __chk_fail optional, to handle building 43 | * with a "mismatched" SDK. This uses dlsym() instead of weak linking. 44 | * 45 | * The inclusion of OS version conditionals. 46 | */ 47 | 48 | /* MP support header */ 49 | #include "MacportsLegacySupport.h" 50 | 51 | /* Note that the support for this mechanism is absent prior to 10.5 */ 52 | #if __MPLS_LIB_SUPPORT_STPNCPY__ && __MPLS_TARGET_OSVER >= 1050 53 | 54 | /* Ensure that we don't create an infinitely recursive check function */ 55 | #undef _FORTIFY_SOURCE 56 | #define _FORTIFY_SOURCE 0 57 | 58 | #include 59 | #include 60 | #include 61 | 62 | char * 63 | __stpncpy_chk (char *dest, const char *src, size_t len, size_t dstlen) 64 | { 65 | void (*chk_fail_p) (void) __attribute__((__noreturn__)); 66 | 67 | if (__builtin_expect (dstlen < len, 0)) { 68 | if ((chk_fail_p = dlsym(RTLD_NEXT, "__chk_fail"))) (*chk_fail_p)(); 69 | abort(); 70 | } 71 | 72 | return stpncpy (dest, src, len); 73 | } 74 | 75 | #endif /* __MPLS_LIB_SUPPORT_STPNCPY__ && >= 10.5 */ 76 | -------------------------------------------------------------------------------- /src/sincos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Chris Jones 3 | * Copyright (c) 2025 Frederick H. G. Wright II 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* MP support header */ 19 | #include "MacportsLegacySupport.h" 20 | 21 | #if __MPLS_LIB_SUPPORT_SINCOS__ 22 | 23 | /* Avoid including math.h to avoid conflicts when building with a later SDK. */ 24 | 25 | extern float cosf(float); 26 | extern double cos(double); 27 | 28 | extern float sinf(float); 29 | extern double sin(double); 30 | 31 | /* Following is borrowed from math.h on macOS 10.9+ */ 32 | 33 | /* __sincos and __sincosf were introduced in OSX 10.9 and iOS 7.0. When 34 | targeting an older system, we simply split them up into discrete calls 35 | to sin( ) and cos( ). */ 36 | void __sincosf(float __x, float *__sinp, float *__cosp) { 37 | *__sinp = sinf(__x); 38 | *__cosp = cosf(__x); 39 | } 40 | void __sincos(double __x, double *__sinp, double *__cosp) { 41 | *__sinp = sin(__x); 42 | *__cosp = cos(__x); 43 | } 44 | 45 | /* 46 | * The following definitions are only used on a 10.7+ build with a 10.9+ SDK. 47 | * 48 | * The comment and declarations are from the 10.9 math.h. 49 | * The function definitions are new. 50 | */ 51 | 52 | /* Implementation details of __sincos and __sincospi allowing them to return 53 | two results while allowing the compiler to optimize away unnecessary load- 54 | store traffic. Although these interfaces are exposed in the math.h header 55 | to allow compilers to generate better code, users should call __sincos[f] 56 | and __sincospi[f] instead and allow the compiler to emit these calls. */ 57 | struct __float2 { float __sinval; float __cosval; }; 58 | struct __double2 { double __sinval; double __cosval; }; 59 | 60 | struct __float2 __sincosf_stret(float __x) 61 | { 62 | const struct __float2 __stret = {.__sinval = sinf(__x), 63 | .__cosval = cosf(__x)}; 64 | return __stret; 65 | } 66 | 67 | struct __double2 __sincos_stret(double __x) 68 | { 69 | const struct __double2 __stret = {.__sinval = sin(__x), 70 | .__cosval = cos(__x)}; 71 | return __stret; 72 | } 73 | 74 | #endif /* __MPLS_LIB_SUPPORT_SINCOS__ */ 75 | -------------------------------------------------------------------------------- /src/stpncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Apple, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | * NOTICE: This file was modified in April 2024 to allow 26 | * for use as a supporting file for MacPorts legacy support library. This notice 27 | * is included in support of clause 2.2 (b) of the Apple Public License, 28 | * Version 2.0. 29 | * 30 | * The code is almost verbatim from Apple except for the removal of the 31 | * 'restrict' qualifiers for compatibility with pre-C99 compilers, and 32 | * the _FORTIFY_SOURCE definition here in lieu of including it as a 33 | * compiler flag (as the Apple build procedure does). 34 | */ 35 | 36 | /* MP support header */ 37 | #include "MacportsLegacySupport.h" 38 | #if __MPLS_LIB_SUPPORT_STPNCPY__ 39 | 40 | /* Ensure that we don't use the wrapper macro when defining the function */ 41 | #undef _FORTIFY_SOURCE 42 | #define _FORTIFY_SOURCE 0 43 | 44 | #include 45 | 46 | char * 47 | stpncpy(char * dst, const char * src, size_t maxlen) { 48 | const size_t srclen = strnlen(src, maxlen); 49 | if (srclen < maxlen) { 50 | // The stpncpy() and strncpy() functions copy at most maxlen 51 | // characters from src into dst. 52 | memcpy(dst, src, srclen); 53 | // If src is less than maxlen characters long, the remainder 54 | // of dst is filled with '\0' characters. 55 | memset(dst+srclen, 0, maxlen-srclen); 56 | // The stpcpy() and stpncpy() functions return a pointer to the 57 | // terminating '\0' character of dst. 58 | return dst+srclen; 59 | } else { 60 | // The stpncpy() and strncpy() functions copy at most maxlen 61 | // characters from src into dst. 62 | memcpy(dst, src, maxlen); 63 | // If stpncpy() does not terminate dst with a NUL character, it 64 | // instead returns a pointer to src[maxlen] (which does not 65 | // necessarily refer to a valid memory location.) 66 | return dst+maxlen; 67 | } 68 | } 69 | 70 | #endif /* __MPLS_LIB_SUPPORT_STPNCPY__ */ 71 | -------------------------------------------------------------------------------- /manual_tests/checksdkversion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This is a manual test to check __MPLS_SDK_MAJOR against the SDK version 19 | * supplied via the SDKVER environment variable (defaulting to the target OS 20 | * version), in the same format as MacOSX.sdk. 21 | */ 22 | 23 | /* Do this before everything else. */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | #include 27 | #include 28 | 29 | #ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 30 | #define TARGET_OS __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 31 | #else 32 | #define TARGET_OS 1040 33 | #endif 34 | 35 | static int 36 | get_sdknum(const char *sdkver) 37 | { 38 | long major, minor; 39 | char *endp; 40 | 41 | if (!sdkver || !*sdkver) return TARGET_OS; 42 | 43 | major = strtol(sdkver, &endp, 10); 44 | if (*endp == '.') { 45 | minor = strtol(endp + 1, &endp, 10); 46 | } else { 47 | minor = 0; 48 | } 49 | if (major < 10 || (major > 10 && minor != 0)) return -1; 50 | if (*endp && (major != 10 || minor != 4 || *endp != 'u')) return -1; 51 | if (major == 10 && minor <= 9) return (int) (major * 100 + minor * 10); 52 | return (int) (major * 10000 + minor * 100); 53 | } 54 | 55 | int 56 | main(int argc, char *argv[]) 57 | { 58 | const char *sdkver = NULL; 59 | int sdknum, sdkmajor; 60 | 61 | (void) argc; (void) argv; 62 | 63 | sdkver = getenv("SDKVER"); 64 | sdknum = get_sdknum(sdkver); 65 | if (sdknum < 0) { 66 | fprintf(stderr, "Bad SDK version: %s\n", sdkver ? sdkver : "???"); 67 | return 20; 68 | } 69 | sdkmajor = sdknum / 10 * 10; 70 | 71 | printf("Testing SDK version %s,%s numeric = %d, major = %d\n", 72 | sdkver ? sdkver : "", sdkver ? "" : " assumed", 73 | sdknum, sdkmajor); 74 | 75 | #ifndef __MPLS_SDK_MAJOR 76 | printf(" __MPLS_SDK_MAJOR is undefined\n"); 77 | return 1; 78 | #else 79 | if (__MPLS_SDK_MAJOR != sdkmajor) { 80 | printf(" __MPLS_SDK_MAJOR is %d, should be %d\n", 81 | __MPLS_SDK_MAJOR, sdkmajor); 82 | return 2; 83 | } else { 84 | printf(" __MPLS_SDK_MAJOR is correctly %d\n", sdkmajor); 85 | } 86 | #endif 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/strings.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | // MP support header 33 | #include "MacportsLegacySupport.h" 34 | 35 | #if __MPLS_LIB_SUPPORT_FFSL__ 36 | int ffsl(long mask) 37 | { 38 | int bit = 0; 39 | if (mask != 0) { 40 | for (bit = 1; !(mask & 1); bit++) { 41 | mask = (unsigned long)mask >> 1; 42 | } 43 | } 44 | return (bit); 45 | } 46 | #endif 47 | 48 | #if __MPLS_LIB_SUPPORT_FFSLL__ 49 | int ffsll(long long mask) 50 | { 51 | int bit = 0; 52 | if (mask != 0) { 53 | for (bit = 1; !(mask & 1); bit++) { 54 | mask = (unsigned long long)mask >> 1; 55 | } 56 | } 57 | return (bit); 58 | } 59 | #endif 60 | 61 | #if __MPLS_LIB_SUPPORT_FLS__ 62 | int fls(int mask) 63 | { 64 | int bit = 0; 65 | if (mask != 0) { 66 | for (bit = 1; mask != 1; bit++) { 67 | mask = (unsigned int)mask >> 1; 68 | } 69 | } 70 | return (bit); 71 | } 72 | #endif 73 | 74 | #if __MPLS_LIB_SUPPORT_FLSL__ 75 | int flsl(long mask) 76 | { 77 | int bit = 0; 78 | if (mask != 0) { 79 | for (bit = 1; mask != 1; bit++) { 80 | mask = (unsigned long)mask >> 1; 81 | } 82 | } 83 | return (bit); 84 | } 85 | #endif 86 | 87 | #if __MPLS_LIB_SUPPORT_FLSLL__ 88 | int flsll(long long mask) 89 | { 90 | int bit = 0; 91 | if (mask != 0) { 92 | for (bit = 1; mask != 1; bit++) { 93 | mask = (unsigned long long)mask >> 1; 94 | } 95 | } 96 | return (bit); 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /include/copyfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_COPYFILE_H_ 18 | #define _MACPORTS_COPYFILE_H_ 19 | 20 | /* MP support header */ 21 | #include "MacportsLegacySupport.h" 22 | 23 | /* Do our SDK-related setup */ 24 | #include <_macports_extras/sdkversion.h> 25 | 26 | #if __MPLS_SDK_SUPPORT_COPYFILE_TIGER__ 27 | 28 | /* The 10.4 SDK lacks copyfile.h, so we provide a substitute. */ 29 | #include <_macports_extras/tiger_only/copyfile.h> 30 | 31 | /* Additional defs from the 10.5 copyfile.h */ 32 | 33 | __MP__BEGIN_DECLS 34 | 35 | int fcopyfile(int from_fd, int to_fd, copyfile_state_t, copyfile_flags_t flags); 36 | 37 | int copyfile_state_free(copyfile_state_t); 38 | copyfile_state_t copyfile_state_alloc(void); 39 | 40 | int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst); 41 | int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src); 42 | 43 | __MP__END_DECLS 44 | 45 | #define COPYFILE_STATE_SRC_FD 1 46 | #define COPYFILE_STATE_SRC_FILENAME 2 47 | #define COPYFILE_STATE_DST_FD 3 48 | #define COPYFILE_STATE_DST_FILENAME 4 49 | #define COPYFILE_STATE_QUARANTINE 5 50 | 51 | #undef COPYFILE_DISABLE_VAR 52 | #define COPYFILE_DISABLE_VAR "COPYFILE_DISABLE" 53 | 54 | #else /* !__MPLS_SDK_SUPPORT_COPYFILE_TIGER__ */ 55 | 56 | /* Otherwise include the primary system copyfile.h */ 57 | #include_next 58 | 59 | #endif /* !__MPLS_SDK_SUPPORT_COPYFILE_TIGER__ */ 60 | 61 | #if __MPLS_SDK_SUPPORT_COPYFILE_10_6__ 62 | 63 | /* Additional defs from the 10.6 copyfile.h */ 64 | 65 | typedef int (*copyfile_callback_t)(int, int, copyfile_state_t, const char *, const char *, void *); 66 | 67 | #define COPYFILE_STATE_STATUS_CB 6 68 | #define COPYFILE_STATE_STATUS_CTX 7 69 | #define COPYFILE_STATE_COPIED 8 70 | 71 | #define COPYFILE_RECURSIVE (1<<15) /* Descend into hierarchies */ 72 | 73 | #define COPYFILE_RECURSE_ERROR 0 74 | #define COPYFILE_RECURSE_FILE 1 75 | #define COPYFILE_RECURSE_DIR 2 76 | #define COPYFILE_RECURSE_DIR_CLEANUP 3 77 | #define COPYFILE_COPY_DATA 4 78 | 79 | #define COPYFILE_START 1 80 | #define COPYFILE_FINISH 2 81 | #define COPYFILE_ERR 3 82 | #define COPYFILE_PROGRESS 4 83 | 84 | #define COPYFILE_CONTINUE 0 85 | #define COPYFILE_SKIP 1 86 | #define COPYFILE_QUIT 2 87 | 88 | #endif /* __MPLS_SDK_SUPPORT_COPYFILE_10_6__ */ 89 | 90 | #endif /* _MACPORTS_COPYFILE_H_ */ 91 | -------------------------------------------------------------------------------- /test/test_stpncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Frederick H. G. Wright II 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This provides rudimentary tests for stpncpy(). Given that 19 | * the implementation is taken almost verbatim from Apple's code for 10.7+, 20 | * exhaustive testing of corner cases shouldn't be necessary. This just 21 | * tests a few cases, primarily to verify that the function can be used at all 22 | * (which is not true prior to 10.7 without this package), though the framework 23 | * should be valid for all possible test cases. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | const char *test_str = "The Quick Brown Fox"; 31 | 32 | #define BUF_LEN 128 /* Generously longer than test_str */ 33 | 34 | static int save_errno; 35 | static char *save_ret; 36 | static char dest[BUF_LEN], save_dest[BUF_LEN]; 37 | 38 | /* Reference implementation of stpncpy() */ 39 | static char * 40 | ref_stpncpy(char *dst, const char *src, size_t n) 41 | { 42 | char *ret; 43 | 44 | if (n <= 0) return dst; 45 | 46 | while (n) { 47 | if ((*dst++ = *src++) == 0) break; 48 | --n; 49 | } 50 | ret = dst - 1; 51 | while (n--) *dst++ = 0; 52 | return *ret ? ret + 1 : ret; 53 | } 54 | 55 | /* Setup prior to test case */ 56 | static void 57 | setup(void) 58 | { 59 | errno = 0; 60 | memset(dest, -1, BUF_LEN); 61 | } 62 | 63 | /* Save all results from first version */ 64 | static void 65 | save(char *ret) 66 | { 67 | save_errno = errno; 68 | save_ret = ret; 69 | memcpy(save_dest, dest, BUF_LEN); 70 | } 71 | 72 | /* Compare results from both versions */ 73 | static void 74 | check(char *ret) 75 | { 76 | assert(errno == save_errno); 77 | assert(ret == save_ret); 78 | assert(memcmp(save_dest, dest, BUF_LEN) == 0); 79 | } 80 | 81 | /* Run one test case */ 82 | static void 83 | test_stpncpy(char *dst, const char *src, size_t n) 84 | { 85 | setup(); 86 | save(ref_stpncpy(dst, src, n)); 87 | check(stpncpy(dst, src, n)); 88 | } 89 | 90 | int 91 | main(int argc, char *argv[]) 92 | { 93 | int test_len = strlen(test_str); 94 | int n; 95 | 96 | (void) argc; (void) argv; 97 | 98 | for (n = test_len - 2; n <= test_len + 2; ++n) { 99 | test_stpncpy(&dest[1], test_str, n); 100 | } 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /src/posix_memalign_emulation.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999, 2006-2008 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | /* 25 | Inspired in part by malloc (aka dlmalloc) of malloc/free/realloc written by 26 | Doug Lea and released to the public domain, as explained at 27 | http://creativecommons.org/publicdomain/zero/1.0/ Send questions, 28 | comments, complaints, performance data, etc to dl@cs.oswego.edu 29 | 30 | * Version 2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea 31 | Note: There may be an updated version of this malloc obtainable at 32 | ftp://gee.cs.oswego.edu/pub/misc/malloc.c 33 | Check before installing! 34 | */ 35 | 36 | /* 37 | * NOTICE: This file was modified in December 2018 to allow 38 | * use as a supporting file for MacPorts legacy support library. This notice 39 | * is included in support of clause 2.2 (b) of the Apple Public License, 40 | * Version 2.0. 41 | */ 42 | 43 | /* MP support header */ 44 | #include "MacportsLegacySupport.h" 45 | 46 | #if __MPLS_LIB_SUPPORT_POSIX_MEMALIGN__ 47 | 48 | #include 49 | #include 50 | 51 | int posix_memalign(void** pp, size_t alignment, size_t bytes) { 52 | 53 | /* if alignment is 0 or not a power of 2 return bad value */ 54 | if (alignment < sizeof( void *) || // excludes 0 == alignment 55 | 0 != (alignment & (alignment - 1))) { // relies on sizeof(void *) being a power of two. 56 | return EINVAL; 57 | } 58 | 59 | void* mem = 0; 60 | 61 | if (alignment <= 16) { 62 | 63 | /* MacOSX always returns memory aligned on 64 | * a 16 byte alignment 65 | */ 66 | mem = malloc(bytes); 67 | 68 | } else { 69 | 70 | /* if the caller wants a larger alignment than 16 71 | * we give them a page-aligned allotment. This is not as efficient 72 | * as an optimized aligned memory implementation, but much 73 | * simpler, effective, and requires no changes to the rest of the 74 | * underlying memory management system. 75 | */ 76 | mem = valloc(bytes); 77 | } 78 | if (mem == 0) 79 | return ENOMEM; 80 | else { 81 | *pp = mem; 82 | return 0; 83 | } 84 | } 85 | 86 | #endif /* __MPLS_LIB_SUPPORT_POSIX_MEMALIGN__ */ 87 | -------------------------------------------------------------------------------- /src/pthread_get_stacksize_np.c: -------------------------------------------------------------------------------- 1 | /* MP support header */ 2 | #include "MacportsLegacySupport.h" 3 | 4 | #if __MPLS_LIB_SUPPORT_PTHREAD_GET_STACKSIZE_NP_FIX__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "util.h" 11 | 12 | #if __MPLS_TARGET_OSVER >= 1090 13 | /* private system call available on OS X Mavericks (version 10.9) and later */ 14 | /* see https://github.com/apple-oss-distributions/libpthread/blob/ba8e1488a0e6848b710c5daad2e226f66cfed656/private/pthread/private.h#L34 */ 15 | pthread_t pthread_main_thread_np(void); 16 | #endif 17 | 18 | #define kMaxThreadStackSize 0x40000000 /* from LLVM: 1 << 30 or 1Gb */ 19 | 20 | size_t pthread_get_stacksize_np(pthread_t t) { 21 | #if __MPLS_TARGET_OSVER >= 1090 22 | int is_main_thread = pthread_equal(t, pthread_main_thread_np()); 23 | #else 24 | /* taken from Apple Libc */ 25 | /* see https://github.com/apple-oss-distributions/Libc/blob/224a8105d573730ae33f474ae5b63b113123aee4/pthreads/pthread.c#L1167 */ 26 | /* for _PTHREAD_CREATE_PARENT, see https://github.com/apple-oss-distributions/Libc/blob/224a8105d573730ae33f474ae5b63b113123aee4/pthreads/pthread_internals.h#L647C9-L647C31 */ 27 | /* for pthread_t, see https://github.com/apple-oss-distributions/Libc/blob/224a8105d573730ae33f474ae5b63b113123aee4/pthreads/pthread_internals.h#L107 */ 28 | /* for pthread_lock_t, see https://github.com/apple-oss-distributions/Libc/blob/224a8105d573730ae33f474ae5b63b113123aee4/pthreads/pthread_machdep.h#L214C13-L214C27 */ 29 | struct 30 | { 31 | long sig; 32 | struct __darwin_pthread_handler_rec *cleanup_stack; 33 | int lock; 34 | __int32_t detached:8, 35 | inherit:8, 36 | policy:8, 37 | freeStackOnExit:1, 38 | newstyle:1, 39 | kernalloc:1, 40 | schedset:1, 41 | wqthread:1, 42 | pad:3; 43 | char opaque[__PTHREAD_SIZE__-sizeof(int)-sizeof(__int32_t)]; 44 | } *thread = (void*) t; 45 | int is_main_thread = ((thread->detached & 4) == 4); 46 | #endif 47 | if ( is_main_thread ) { 48 | /* use LLVM workaround */ 49 | /* see https://github.com/llvm/llvm-project/blob/617a15a9eac96088ae5e9134248d8236e34b91b1/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L414 */ 50 | /* OpenJDK also has a workaround */ 51 | /* see https://github.com/openjdk/jdk/blob/e833bfc8ac6104522d037e7eb300f5aa112688bb/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp#L715 */ 52 | struct rlimit limit; 53 | if( getrlimit(RLIMIT_STACK, &limit) ) { 54 | exit(EXIT_FAILURE); 55 | } 56 | if( limit.rlim_cur < kMaxThreadStackSize ) { 57 | return limit.rlim_cur; 58 | } else { 59 | return kMaxThreadStackSize; 60 | } 61 | } else { 62 | /* bug only affects main thread */ 63 | GET_OS_FUNC(pthread_get_stacksize_np) 64 | return (*os_pthread_get_stacksize_np)(t); 65 | } 66 | } 67 | 68 | #endif /* __MPLS_LIB_SUPPORT_PTHREAD_GET_STACKSIZE_NP_FIX__ */ 69 | -------------------------------------------------------------------------------- /include/sys/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Chris Jones 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _MACPORTS_SYS_QUEUE_H_ 18 | #define _MACPORTS_SYS_QUEUE_H_ 19 | 20 | /* Include the primary system sys/queue.h */ 21 | #include_next 22 | 23 | /* 24 | * When SDK 10.15+ versions are built with clang, they define a pair of 25 | * macros to disable "nullability completeness" warnings. See the comment 26 | * for details. But attempting to disable this warning in compilers that 27 | * don't have it provokes a warning of its own. So we nuke those macros 28 | * in such cases. 29 | * 30 | * This is complicated by the fact that the clang version threshold for 31 | * implementing nullability completeness differs between Xcode and MacPorts 32 | * clangs. MacPorts clang has it as of 3.7, but Xcode clang doesn't have 33 | * it until 7.x. 34 | * 35 | * Note that the SDK's example of where the workaround is needed doesn't 36 | * actually work, so we don't have a test that this works correctly, beyond 37 | * getting rid of the warnings with older clangs. 38 | */ 39 | #if defined(__NULLABILITY_COMPLETENESS_PUSH) && defined(__clang__) 40 | #if (__clang_major__ < 4 || __clang_minor__ < 7) \ 41 | || (defined(__apple_build_version__) && __clang_major__ < 7) 42 | #undef __NULLABILITY_COMPLETENESS_PUSH 43 | #undef __NULLABILITY_COMPLETENESS_POP 44 | #define __NULLABILITY_COMPLETENESS_PUSH 45 | #define __NULLABILITY_COMPLETENESS_POP 46 | #endif /* Early clang */ 47 | #endif /* __NULLABILITY_COMPLETENESS_PUSH */ 48 | 49 | 50 | /* SLIST functions missing from earlier SDK versions */ 51 | 52 | /* Missing until 10.5 */ 53 | 54 | #ifndef SLIST_HEAD_INITIALIZER 55 | #define SLIST_HEAD_INITIALIZER(head) \ 56 | { NULL } 57 | #endif 58 | 59 | /* Missing until 10.7 */ 60 | 61 | #ifndef SLIST_REMOVE_AFTER 62 | #define SLIST_REMOVE_AFTER(elm, field) do { \ 63 | SLIST_NEXT(elm, field) = \ 64 | SLIST_NEXT(SLIST_NEXT(elm, field), field); \ 65 | } while (0) 66 | #endif 67 | 68 | /* STAILQ functions missing from earlier SDK versions */ 69 | 70 | /* Missing until 10.5 */ 71 | 72 | #ifndef STAILQ_FOREACH 73 | #define STAILQ_FOREACH(var, head, field) \ 74 | for((var) = STAILQ_FIRST((head)); \ 75 | (var); \ 76 | (var) = STAILQ_NEXT((var), field)) 77 | #endif 78 | 79 | #endif /* _MACPORTS_SYS_QUEUE_H_ */ 80 | -------------------------------------------------------------------------------- /include/cmath: -------------------------------------------------------------------------------- 1 | /* -*- c++ -*- */ 2 | /* 3 | * Copyright (c) 2019 Michael Dickens 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MACPORTS_CMATH_ 19 | #define _MACPORTS_CMATH_ 20 | 21 | /* include MP support header to see if c++11 cmath support is needed */ 22 | #include "MacportsLegacySupport.h" 23 | 24 | #if __MP_LEGACY_SUPPORT_CXX11_CMATH__ 25 | 26 | /* 27 | * NOTE: This has to come -before- the include_next, so that the 28 | * setting is valid for any subsequently included header. 29 | */ 30 | 31 | #undef L_GLIBCXX_USE_C99_MATH_TR1 32 | #ifndef _GLIBCXX_USE_C99_MATH_TR1 33 | #define L_GLIBCXX_USE_C99_MATH_TR1 1 34 | 35 | /* 36 | * this macro enables c++11 math support in g++. It just needs to be 37 | * defined; not to any particular value; use 1 just because. 38 | */ 39 | #define _GLIBCXX_USE_C99_MATH_TR1 1 40 | #endif 41 | 42 | /* 43 | * Include our local math.h. NOTE: This has to come -before- the 44 | * include_next for , so that the top-level functions are 45 | * all declared before they are referenced. 46 | */ 47 | #include 48 | #endif /* __MP_LEGACY_SUPPORT_CXX11_CMATH__ */ 49 | 50 | /* 51 | * Include the next cmath, which might be from the primary system or 52 | * it might be within GCC's c++ headers; either is OK here. 53 | */ 54 | #include_next 55 | 56 | #if __MP_LEGACY_SUPPORT_CXX11_CMATH__ 57 | 58 | #ifdef L_GLIBCXX_USE_C99_MATH_TR1 59 | #undef _GLIBCXX_USE_C99_MATH_TR1 60 | #undef L_GLIBCXX_USE_C99_MATH_TR1 61 | #endif 62 | 63 | /* 64 | * this is the same condition that defines the function prototypes in 65 | * the system . 66 | */ 67 | #if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) 68 | #else 69 | #ifdef _GLIBCXX_NO_C99_ROUNDING_FUNCS 70 | /* have to define these ourselves because GCC doesn't properly */ 71 | #if __cplusplus >= 201103L 72 | 73 | #undef llrint 74 | #undef llrintf 75 | #undef llrintl 76 | #undef llround 77 | #undef llroundf 78 | #undef llroundl 79 | 80 | namespace std _GLIBCXX_VISIBILITY(default) 81 | { 82 | _GLIBCXX_BEGIN_NAMESPACE_VERSION 83 | using ::llrint; 84 | using ::llrintf; 85 | using ::llrintl; 86 | using ::llround; 87 | using ::llroundf; 88 | using ::llroundl; 89 | _GLIBCXX_END_NAMESPACE_VERSION 90 | } // namespace 91 | 92 | #endif /* __cplusplus >= 201103L */ 93 | #endif /* _GLIBCXX_NO_C99_ROUNDING_FUNCS */ 94 | #endif /* various */ 95 | #endif /* __MP_LEGACY_SUPPORT_CXX11_CMATH__ */ 96 | #endif /* _MACPORTS_CMATH_ */ 97 | -------------------------------------------------------------------------------- /src/fsgetpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 3 | * from an example posted in Apple Developer Support 4 | * https://forums.developer.apple.com/thread/103162 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* MP support header */ 20 | #include "MacportsLegacySupport.h" 21 | #if __MPLS_LIB_SUPPORT_FSGETPATH__ 22 | 23 | #if 1 24 | /* SYS_fsgetpath is only available on 10.6 and up */ 25 | #if __APPLE__ && __MPLS_TARGET_OSVER >= 1060 26 | /* implement using a syscall available macOS 10.6 to 10.12 */ 27 | /* this should be thoroughly vetted as a syscall, but is private API */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | ssize_t fsgetpath(char * buf, size_t buflen, fsid_t * fsid, uint64_t obj_id) { 33 | return (ssize_t)syscall(SYS_fsgetpath, buf, (size_t)buflen, fsid, (uint64_t)obj_id); 34 | } 35 | #endif 36 | #endif 37 | 38 | #if 0 39 | /* implement with a compatability function that presently compiles on 10.6 and over */ 40 | /* this may be better (see linked post above) but it's hard to thoroughly test it. */ 41 | /* this may also be able to be expanded to cover 10.4 and 10.5 if we can workaround ATTR_CMN_FULLPATH */ 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | ssize_t fsgetpath(char * buf, size_t buflen, fsid_t * fsid, uint64_t obj_id) { 50 | char volfsPath[64]; // 8 for `/.vol//\0`, 10 for `fsid->val[0]`, 20 for `obj_id`, rounded up for paranoia 51 | 52 | snprintf(volfsPath, sizeof(volfsPath), "/.vol/%ld/%llu", (long) fsid->val[0], (unsigned long long) obj_id); 53 | 54 | struct { 55 | uint32_t length; 56 | attrreference_t pathRef; 57 | char buffer[MAXPATHLEN]; 58 | } __attribute__((aligned(4), packed)) attrBuf; 59 | 60 | struct attrlist attrList; 61 | memset(&attrList, 0, sizeof(attrList)); 62 | attrList.bitmapcount = ATTR_BIT_MAP_COUNT; 63 | attrList.commonattr = ATTR_CMN_FULLPATH; 64 | 65 | int success = getattrlist(volfsPath, &attrList, &attrBuf, sizeof(attrBuf), 0) == 0; 66 | if ( ! success ) { 67 | return -1; 68 | } 69 | if (attrBuf.pathRef.attr_length > buflen) { 70 | errno = ENOSPC; 71 | return -1; 72 | } 73 | strlcpy(buf, ((const char *) &attrBuf.pathRef) + attrBuf.pathRef.attr_dataoffset, buflen); 74 | return attrBuf.pathRef.attr_length; 75 | } 76 | #endif 77 | 78 | #endif /* __MPLS_LIB_SUPPORT_FSGETPATH__ */ 79 | -------------------------------------------------------------------------------- /src/pthread_chdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025 Frederick H. G. Wright II 3 | * 4 | * 5 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 6 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 9 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 10 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 11 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 12 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 13 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 14 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 15 | * SUCH DAMAGE. 16 | */ 17 | 18 | /* MP support header */ 19 | #include "MacportsLegacySupport.h" 20 | 21 | #if __MPLS_LIB_SUPPORT_PTHREAD_CHDIR__ 22 | /* 23 | * The pthread_[f]chdir_np() functions are available as syscalls starting 24 | * in 10.5, but not as functions until 10.12. This provides the missing 25 | * function wrappers where needed. 26 | */ 27 | 28 | #define _MACPORTS_LEGACY_PTHREAD_CHDIR 1 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | int 35 | pthread_chdir_np(const char* path) 36 | { 37 | return syscall(SYS___pthread_chdir, path); 38 | } 39 | 40 | int 41 | pthread_fchdir_np(int fd) 42 | { 43 | return syscall(SYS___pthread_fchdir, fd); 44 | } 45 | 46 | #endif /* __MPLS_LIB_SUPPORT_PTHREAD_CHDIR__ */ 47 | 48 | #if __MPLS_LIB_DUMMY_PTHREAD_CHDIR__ 49 | /* 50 | * Dummy versions of the functions, in case the client builds with a 10.5+ SDK 51 | * but runs on 10.4. There's no truly appropriate choice for errno, so we 52 | * pick ENXIO as one that's somewhat mnemonic and not likely to occur with 53 | * the real functions. 54 | */ 55 | 56 | #include 57 | 58 | int 59 | pthread_chdir_np(const char* path) 60 | { 61 | (void) path; 62 | errno = ENXIO; 63 | return -1; 64 | } 65 | 66 | int 67 | pthread_fchdir_np(int fd) 68 | { 69 | (void) fd; 70 | errno = ENXIO; 71 | return -1; 72 | } 73 | 74 | #endif /* __MPLS_LIB_DUMMY_PTHREAD_CHDIR__ */ 75 | 76 | #if __MPLS_LIB_NEED_BEST_FCHDIR__ 77 | /* 78 | * Provide a per-thread fchdir() for the ATCALL code if possible, but 79 | * fall back to the (thread-unsafe) process-level version if not (10.4). 80 | */ 81 | 82 | #if !__MPLS_LIB_DUMMY_PTHREAD_CHDIR__ 83 | 84 | #define _MACPORTS_LEGACY_PTHREAD_CHDIR 1 85 | #include 86 | 87 | int 88 | __mpls_best_fchdir(int dirfd) 89 | { 90 | return pthread_fchdir_np(dirfd); 91 | } 92 | 93 | #else /* __MPLS_LIB_DUMMY_PTHREAD_CHDIR__ */ 94 | 95 | #include 96 | 97 | int 98 | __mpls_best_fchdir(int dirfd) 99 | { 100 | /* 101 | * Accept dirfd == -1 (return to process cwd in __pthread_fchdir), 102 | * but do nothing with it. 103 | */ 104 | if (dirfd == -1) return 0; 105 | return fchdir(dirfd); 106 | } 107 | 108 | #endif /* __MPLS_LIB_DUMMY_PTHREAD_CHDIR__ */ 109 | 110 | #endif /* __MPLS_LIB_NEED_BEST_FCHDIR__ */ 111 | --------------------------------------------------------------------------------