- (let ((result (c-inotify-init)))
- (when (minusp result)
- (perror "inotify_init failed"))
- (with-slots (fd stream (non-block nonblocking)) inotify
- (unwind-protect
- ;; file descriptor is collected with auto-close
- (progn
- (setf fd result)
- (when nonblocking
- (set-nonblocking fd T)
- (setf non-block nonblocking))
- (setf stream
- (sb-sys:make-fd-stream
- fd
- :input T
- :element-type '(unsigned-byte 8)
- :name (format NIL "inotify event queue ~A" fd)
- :auto-close T
- :buffering (if nonblocking :none :full))))
- ;; if stream is constructed, gc'ing it will cleanup the file descriptor
- (unless stream
- (sb-posix:close fd)))))
+ (with-slots (fd stream (non-block nonblocking)) inotify
+ (unwind-protect
+ ;; file descriptor is collected with auto-close
+ (progn
+ (setf fd (inotify-init1 (and (setf non-block nonblocking)
+ :nonblock)))
+ (setf stream
+ ;; TODO: what about the blocking?
+ #-(or clisp sbcl)
+ (osicat::make-fd-stream
+ fd
+ :direction :input
+ :element-type '(unsigned-byte 8))
+ #+clisp
+ (ext:make-stream
+ fd
+ :direction :input
+ :element-type '(unsigned-byte 8)
+ :buffered (not nonblocking))
+ #+sbcl
+ (sb-sys:make-fd-stream
+ fd
+ :input T
+ :element-type '(unsigned-byte 8)
+ :name (format NIL "inotify event queue ~A" fd)
+ :auto-close T
+ :buffering (if nonblocking :none :full))))
+ ;; if stream is constructed, gc'ing it will cleanup the file descriptor
+ ;; TODO: is this true for clisp? because the docs say that
+ ;; EXT:MAKE-STREAM uses dup(2)
+ (unless stream
+ (osicat-posix:close fd))))