mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
These are contexts where we have enough information to bridge /back/ properly; that is, where we can distinguish CBool, ObjCBool, and DarwinBoolean. In cases where we can't, we keep the three separate; only CBool is really the same type as Bool. This also affects current import behavior for ObjCBool, which was previously incorrectly conflated with CBool in certain cases. More rdar://problem/19013551 Swift SVN r30051
231 lines
6.2 KiB
Swift
231 lines
6.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@exported import Darwin // Clang module
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// MacTypes.h
|
|
//===----------------------------------------------------------------------===//
|
|
public let noErr: OSStatus = 0
|
|
|
|
/// The `Boolean` type declared in MacTypes.h and used throughout Core
|
|
/// Foundation.
|
|
///
|
|
/// The C type is a typedef for `unsigned char`.
|
|
public struct DarwinBoolean : BooleanType, BooleanLiteralConvertible {
|
|
var value: UInt8
|
|
|
|
public init(_ value: Bool) {
|
|
self.value = value ? 1 : 0
|
|
}
|
|
|
|
/// The value of `self`, expressed as a `Bool`.
|
|
public var boolValue: Bool {
|
|
return value != 0
|
|
}
|
|
|
|
/// Create an instance initialized to `value`.
|
|
@transparent
|
|
public init(booleanLiteral value: Bool) {
|
|
self.init(value)
|
|
}
|
|
}
|
|
|
|
extension DarwinBoolean : _Reflectable {
|
|
/// Returns a mirror that reflects `self`.
|
|
public func _getMirror() -> _MirrorType {
|
|
return _reflect(boolValue)
|
|
}
|
|
}
|
|
|
|
extension DarwinBoolean : CustomStringConvertible {
|
|
/// A textual representation of `self`.
|
|
public var description: String {
|
|
return self.boolValue.description
|
|
}
|
|
}
|
|
|
|
extension DarwinBoolean : Equatable {}
|
|
public func ==(lhs: DarwinBoolean, rhs: DarwinBoolean) -> Bool {
|
|
return lhs.boolValue == rhs.boolValue
|
|
}
|
|
|
|
public // COMPILER_INTRINSIC
|
|
func _convertBoolToDarwinBoolean(x: Bool) -> DarwinBoolean {
|
|
return DarwinBoolean(x)
|
|
}
|
|
public // COMPILER_INTRINSIC
|
|
func _convertDarwinBooleanToBool(x: DarwinBoolean) -> Bool {
|
|
return Bool(x)
|
|
}
|
|
|
|
// FIXME: We can't make the fully-generic versions @transparent due to
|
|
// rdar://problem/19418937, so here are some @transparent overloads
|
|
// for DarwinBoolean.
|
|
@transparent
|
|
public func && <T : BooleanType>(
|
|
lhs: T, @autoclosure rhs: () -> DarwinBoolean
|
|
) -> Bool {
|
|
return lhs.boolValue ? rhs().boolValue : false
|
|
}
|
|
|
|
@transparent
|
|
public func || <T : BooleanType>(
|
|
lhs: T, @autoclosure rhs: () -> DarwinBoolean
|
|
) -> Bool {
|
|
return lhs.boolValue ? true : rhs().boolValue
|
|
}
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// sys/errno.h
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
public var errno : Int32 {
|
|
get {
|
|
return __error().memory
|
|
}
|
|
set {
|
|
__error().memory = newValue
|
|
}
|
|
}
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// stdio.h
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
public var stdin : UnsafeMutablePointer<FILE> {
|
|
get {
|
|
return __stdinp
|
|
}
|
|
set {
|
|
__stdinp = newValue
|
|
}
|
|
}
|
|
|
|
public var stdout : UnsafeMutablePointer<FILE> {
|
|
get {
|
|
return __stdoutp
|
|
}
|
|
set {
|
|
__stdoutp = newValue
|
|
}
|
|
}
|
|
|
|
public var stderr : UnsafeMutablePointer<FILE> {
|
|
get {
|
|
return __stderrp
|
|
}
|
|
set {
|
|
__stderrp = newValue
|
|
}
|
|
}
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// fcntl.h
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@asmname("_swift_Darwin_open")
|
|
func _swift_Darwin_open(path: UnsafePointer<CChar>,
|
|
_ oflag: CInt, _ mode: mode_t) -> CInt
|
|
@asmname("_swift_Darwin_openat")
|
|
func _swift_Darwin_openat(fd: CInt,
|
|
_ path: UnsafePointer<CChar>,
|
|
_ oflag: CInt, _ mode: mode_t) -> CInt
|
|
|
|
public func open(path: UnsafePointer<CChar>, _ oflag: CInt) -> CInt {
|
|
return _swift_Darwin_open(path, oflag, 0)
|
|
}
|
|
|
|
public func open(path: UnsafePointer<CChar>, _ oflag: CInt,
|
|
_ mode: mode_t) -> CInt {
|
|
return _swift_Darwin_open(path, oflag, mode)
|
|
}
|
|
|
|
public func openat(fd: CInt, _ path: UnsafePointer<CChar>,
|
|
_ oflag: CInt) -> CInt {
|
|
return _swift_Darwin_openat(fd, path, oflag, 0)
|
|
}
|
|
|
|
public func openat(fd: CInt, _ path: UnsafePointer<CChar>,
|
|
_ oflag: CInt, _ mode: mode_t) -> CInt {
|
|
return _swift_Darwin_openat(fd, path, oflag, mode)
|
|
}
|
|
|
|
|
|
public let S_IFMT = mode_t(0o170000)
|
|
public let S_IFIFO = mode_t(0o010000)
|
|
public let S_IFCHR = mode_t(0o020000)
|
|
public let S_IFDIR = mode_t(0o040000)
|
|
public let S_IFBLK = mode_t(0o060000)
|
|
public let S_IFREG = mode_t(0o100000)
|
|
public let S_IFLNK = mode_t(0o120000)
|
|
public let S_IFSOCK = mode_t(0o140000)
|
|
public let S_IFWHT = mode_t(0o160000)
|
|
|
|
public let S_IRWXU = mode_t(0o000700)
|
|
public let S_IRUSR = mode_t(0o000400)
|
|
public let S_IWUSR = mode_t(0o000200)
|
|
public let S_IXUSR = mode_t(0o000100)
|
|
|
|
public let S_IRWXG = mode_t(0o000070)
|
|
public let S_IRGRP = mode_t(0o000040)
|
|
public let S_IWGRP = mode_t(0o000020)
|
|
public let S_IXGRP = mode_t(0o000010)
|
|
|
|
public let S_IRWXO = mode_t(0o000007)
|
|
public let S_IROTH = mode_t(0o000004)
|
|
public let S_IWOTH = mode_t(0o000002)
|
|
public let S_IXOTH = mode_t(0o000001)
|
|
|
|
public let S_ISUID = mode_t(0o004000)
|
|
public let S_ISGID = mode_t(0o002000)
|
|
public let S_ISVTX = mode_t(0o001000)
|
|
|
|
public let S_ISTXT = S_ISVTX
|
|
public let S_IREAD = S_IRUSR
|
|
public let S_IWRITE = S_IWUSR
|
|
public let S_IEXEC = S_IXUSR
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// unistd.h
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@available(*, unavailable, message="Please use threads or posix_spawn*()")
|
|
public func fork() -> Int32 {
|
|
fatalError("unavailable function can't be called")
|
|
}
|
|
|
|
@available(*, unavailable, message="Please use threads or posix_spawn*()")
|
|
public func vfork() -> Int32 {
|
|
fatalError("unavailable function can't be called")
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// signal.h
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
|
|
public let SIG_DFL: sig_t? = nil
|
|
public let SIG_IGN = unsafeBitCast(1, sig_t.self)
|
|
public let SIG_ERR = unsafeBitCast(-1, sig_t.self)
|
|
public let SIG_HOLD = unsafeBitCast(5, sig_t.self)
|
|
#endif
|
|
|
|
// ${'Local Variables'}:
|
|
// eval: (read-only-mode 1)
|
|
// End:
|