Repository: apple/swift-nio
File: Sources/NIOPosix/System.swift (Swift)

Code before:
private let sysLseek = lseek
private let sysPoll = poll
#endif

#if os(Android)
func sysRecvFrom_wrapper(
    sockfd: CInt,
    buf: UnsafeMutableRawPointer,
    len: CLong,
    flags: CInt,
    src_addr: UnsafeMutablePointer<sockaddr>,
    addrlen: UnsafeMutablePointer<socklen_t>
) -> CLong {
    // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
    recvfrom(sockfd, buf, len, flags, src_addr, addrlen)
    // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
}
func sysWritev_wrapper(fd: CInt, iov: UnsafePointer<iovec>?, iovcnt: CInt) -> CLong {
    CLong(writev(fd, iov!, iovcnt))  // cast 'Int32' to 'CLong'// cast 'Int32' to 'CLong'
}
private let sysWritev = sysWritev_wrapper
#elseif !os(Windows)
private let sysWritev: @convention(c) (Int32, UnsafePointer<iovec>?, CInt) -> CLong = writev
#endif
#if !os(Windows)
private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>?, CInt) -> ssize_t = recvmsg
private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>?, CInt) -> ssize_t = sendmsg
#endif
private let sysDup: @convention(c) (CInt) -> CInt = dup
#if !os(Windows)
private let sysGetpeername:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getpeername
private let sysGetsockname:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getsockname
#endif

#if os(Android)
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsignedInt = if_nametoindex
#else
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
#endif
#if !os(Windows)
private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>?) -> CInt = socketpair
#endif

#if os(Linux) || os(Android) || canImport(Darwin)
private let sysFstat = fstat
private let sysStat = stat
private let sysLstat = lstat
private let sysSymlink = symlink
private let sysReadlink = readlink

Review comment (suggestion):
[These nullability annotations were added with NDK 27](https://android.googlesource.com/platform/bionic/+/4e274fa0a985bdcc0d0e312a8caf381271875877%5E%21/#F0) this summer, so adapt these networking APIs for that.

Code after:
private let sysLseek = lseek
private let sysPoll = poll
#endif

#if os(Android)
func sysRecvFrom_wrapper(
    sockfd: CInt,
    buf: UnsafeMutableRawPointer,
    len: CLong,
    flags: CInt,
    src_addr: UnsafeMutablePointer<sockaddr>,
    addrlen: UnsafeMutablePointer<socklen_t>
) -> CLong {
    // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
    recvfrom(sockfd, buf, len, flags, src_addr, addrlen)
    // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
}
func sysWritev_wrapper(fd: CInt, iov: UnsafePointer<iovec>?, iovcnt: CInt) -> CLong {
    CLong(writev(fd, iov!, iovcnt))  // cast 'Int32' to 'CLong'// cast 'Int32' to 'CLong'
}
private let sysWritev = sysWritev_wrapper
#elseif !os(Windows)
private let sysWritev: @convention(c) (Int32, UnsafePointer<iovec>?, CInt) -> CLong = writev
#endif
#if canImport(Android)
private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>, CInt) -> ssize_t = recvmsg
private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>, CInt) -> ssize_t = sendmsg
#elseif !os(Windows)
private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>?, CInt) -> ssize_t = recvmsg
private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>?, CInt) -> ssize_t = sendmsg
#endif
private let sysDup: @convention(c) (CInt) -> CInt = dup
#if canImport(Android)
private let sysGetpeername:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getpeername
private let sysGetsockname:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getsockname
#elseif !os(Windows)
private let sysGetpeername:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getpeername
private let sysGetsockname:
    @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getsockname
#endif

#if os(Android)
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsignedInt = if_nametoindex
#else
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
#endif
#if canImport(Android)
private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>) -> CInt = socketpair