   }
 
 }
+
+let Sys = PosixSys()

import Glibc


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

class Sys {

  static let DEFAULT_DIR_MODE = S_IRWXU | S_IRWXG | S_IRWXO

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

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

    } else {
      throw SysError.InvalidOpenFileOperation(operation: operation)
    }
    flags |= O_CLOEXEC
    return retry({ csua_open(filePath, flags, mode) })
  }

  public func fflush(stream: UnsafeMutablePointer<FILE> = nil) -> Int32 {
    return _fflush(stream)
  }

  public func getpid() -> Int32 {
    return _getpid()
  }

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