eufon

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

iostream.fnl (513B)


      1 (local posix (require :posix))
      2 (local fcntl (require :posix.fcntl))
      3 
      4 (fn from-descriptor [fd]
      5   {
      6    :read #(posix.unistd.read fd $2)   ;XXX needs to check for eof
      7    :close #(posix.unistd.close fd)
      8    :fileno fd
      9    })
     10 
     11 
     12 (fn open [name direction]
     13   (let [flags (match direction
     14                 :r posix.O_RDONLY
     15                 :w (+ posix.O_WRONLY posix.O_CREAT))
     16         fd (posix.open name flags)]
     17     (fcntl.fcntl fd fcntl.F_SETFL fcntl.O_NONBLOCK)
     18     (from-descriptor fd)))
     19 
     20 {
     21  : open
     22  : from-descriptor
     23  }