 
 
 func wrapSyscallMayBlock(_ successCondition: (Int) -> Bool,
-                 function: @autoclosure () -> String, _ fn: () -> Int) throws -> IOResult<Int> {
-    do {
-        return try .processed(withErrno(successCondition: successCondition, fn))
-    } catch let e as Errno.POSIXError {
-        if e.code == EWOULDBLOCK {
-            return .wouldBlock
+                         function: @autoclosure () -> String, _ fn: () -> Int) throws -> IOResult<Int> {
+    loop: repeat {
+        let result = fn()
+        guard successCondition(result) else {
+            let err = errno
+            switch err {
+            case EWOULDBLOCK:
+                return .wouldBlock
+            case EINTR:
+                continue loop
+            default:
+                testForBlacklistedErrno(err)
+                throw ioError(errno: err, function: function())
+            }
         }
-        testForBlacklistedErrno(e.code)
-        throw ioError(errno: e.code, function: function())
-    }
+        return .processed(result)
+    } while true
 }
 
 func wrapSyscall(function: @autoclosure () -> String,
                  _ successCondition: (Int32) -> Bool, _ fn: () -> Int32) throws -> Int32 {
-    do {
-        return try withErrno(successCondition: successCondition, fn)
-    } catch let e as Errno.POSIXError {
-        testForBlacklistedErrno(e.code)
-        throw ioError(errno: e.code, function: function())
+    let result = fn()
+    guard successCondition(result) else {
+        let err = errno
+        testForBlacklistedErrno(err)
+        throw ioError(errno: err, function: function())
     }
+    return result
 }
 
 func wrapSyscall(_ successCondition: (Int32) -> Bool,


private func testForBlacklistedErrno(_ code: Int32) {
    switch code {
        case EFAULT:
            fallthrough
        case EBADF:
            fatalError("blacklisted errno \(code) \(strerror(code)!)")
        default:
            ()
    }
}

func wrapSyscall(function: @autoclosure () -> String,
                    _ successCondition: (Int) -> Bool, _ fn: () -> Int) throws -> Int {
    do {
        return try withErrno(successCondition: successCondition, fn)
    } catch let e as Errno.POSIXError {
        testForBlacklistedErrno(e.code)
        throw ioError(errno: e.code, function: function())
    }
}

func wrapSyscall(_ successCondition: (Int) -> Bool,
                        function: @autoclosure () -> String, _ fn: () -> Int) throws -> Int {
    return try wrapSyscall(function: function, successCondition, fn)
}



func wrapSyscallMayBlock(_ successCondition: (Int32) -> Bool,
                         function: @autoclosure () -> String, _ fn: () -> Int32) throws -> IOResult<Int32> {
    
    loop: repeat {
        let result = fn()
        guard successCondition(result) else {
            let err = errno
            switch err {
            case EWOULDBLOCK:
                return .wouldBlock
            case EINTR:
                continue loop
            default:
                testForBlacklistedErrno(err)
                throw ioError(errno: err, function: function())
            }
        }
        return .processed(result)
    } while true
}
