| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- This source file is part of the Swift System open source project
- Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors
- Licensed under Apache License v2.0 with Runtime Library Exception
- See https://swift.org/LICENSE.txt for license information
- */
- #if defined(__FreeBSD__)
- #define __BSD_VISIBLE
- #endif
- #if defined(__FreeBSD__) || defined(__OpenBSD__)
- #include <unistd.h>
- #endif
- #if defined(__FreeBSD__)
- #include <CSystemFreeBSD.h>
- #endif
- #ifdef __linux__
- #define _GNU_SOURCE
- #include <CSystemLinux.h>
- #endif
- #if defined(_WIN32)
- #include <CSystemWindows.h>
- #endif
- #include <errno.h>
- #if !defined(_WIN32) && !defined(__wasi__) && !defined(__APPLE__)
- #define HAVE_PIPE2_DUP3
- #endif
- #if defined(__APPLE__)
- #include <Availability.h>
- #if defined(__MAC_27_0)
- #include <unistd.h>
- #define HAVE_PIPE2_DUP3
- #endif
- #endif // defined(__APPLE__)
- // Wrappers are required because _GNU_SOURCE causes a conflict with other imports when defined in CSystemLinux.h
- #if !defined(_WIN32)
- extern int csystem_posix_pipe2(int fildes[2], int flag) {
- #if defined(__APPLE__) && defined(HAVE_PIPE2_DUP3)
- if (__builtin_available(macOS 27, iOS 27, tvOS 27, watchOS 27, visionOS 27, *))
- return pipe2(fildes, flag);
- __builtin_trap();
- #elif defined(HAVE_PIPE2_DUP3)
- return pipe2(fildes, flag);
- #else
- errno = ENOSYS;
- return -1;
- #endif
- }
- #endif // !defined(_WIN32)
- extern int csystem_posix_dup3(int fildes, int fildes2, int flag) {
- #if defined(__APPLE__) && defined(HAVE_PIPE2_DUP3)
- if (__builtin_available(macOS 27, iOS 27, tvOS 27, watchOS 27, visionOS 27, *))
- return dup3(fildes, fildes2, flag);
- __builtin_trap();
- #elif defined(HAVE_PIPE2_DUP3)
- return dup3(fildes, fildes2, flag);
- #else
- errno = ENOSYS;
- return -1;
- #endif
- }
|