Hash :
d4dfedbd
Author :
Thomas de Grivel
Date :
2019-10-27T16:27:57
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
(in-package :unistd-stream)
(defun compute-flags (read write append non-blocking create)
(logior (if append fcntl:+o-append+ 0)
(if non-blocking fcntl:+o-nonblock+ 0)
(if create fcntl:+o-creat+ 0)
(cond ((and read write) fcntl:+o-rdwr+)
(read fcntl:+o-rdonly+)
(write fcntl:+o-wronly+)
(t 0))))
(defun compute-class (read write)
(cond ((and read write) 'unistd-io-stream)
(read 'unistd-input-stream)
(write 'unistd-output-stream)))
(defun compute-mode (create)
(cond ((null create) nil)
((eq t create) #o666)
(t create)))
(defun unistd-stream-open (pathname &key
read write append
non-blocking
(create #o666)
(input-buffer-size
*stream-default-buffer-size*)
(output-buffer-size
*stream-default-buffer-size*))
(assert (or read write)
(read write)
"Open not for reading nor writing.")
(when (pathnamep pathname)
(setq pathname (namestring pathname)))
(let* ((flags (compute-flags read write append non-blocking create))
(mode (compute-mode create))
(fd (fcntl:open pathname flags mode))
(class (compute-class read write))
(args ()))
(when read
(setf args (list* :input-buffer-size input-buffer-size args)))
(when write
(setf args (list* :output-buffer-size output-buffer-size args)))
(apply #'make-instance class :fd fd args)))