   }
 
 }
+
+let Sys = PosixSys()

    } else {
      throw SysError.InvalidOpenFileOperation(operation: operation)
    }
    flags |= O_CLOEXEC;
    let fd = retry({ csua_open(filePath, flags, mode) })
    //ForeignMemory cPath = new ForeignMemory.fromStringAsUTF8(filePath);
    //int fd = _retry(() => _open.icall$3(cPath, flags, mode));
    //cPath.free();
    return fd;
  }

  static func retry(fn: () -> Int32) -> Int32 {
    var value = fn()
    while value == -1 {
      if (errno != EINTR) { break }

import Glibc


public enum SysError: ErrorType {
    case InvalidOpenFileOperation(operation: String)
}

let _fflush = fflush;
let _getpid = getpid;

public class PosixSys {

  public static let DEFAULT_DIR_MODE = S_IRWXU | S_IRWXG | S_IRWXO

  public static let DEFAULT_FILE_MODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
      S_IROTH

  public func openFile(filePath: String, operation: String = "r",
      mode: UInt32 = DEFAULT_FILE_MODE) throws -> Int32 {
    var flags: Int32 = 0
    if operation == "r" {
