checking fd state before call %tcsetattr for restoring originall settings (cause some errors under clisp because it's with-open-stream call close twice)

Nikolay V. Razbegaev [2009-10-23 07:15]
checking fd state before call %tcsetattr for restoring originall settings (cause some errors under clisp because it's with-open-stream call close twice)
Filename
streams.lisp
diff --git a/streams.lisp b/streams.lisp
index 53123fc..998dfa9 100644
--- a/streams.lisp
+++ b/streams.lisp
@@ -29,9 +29,10 @@
 ;; (which call %sys-close) is :around too.
 (defmethod close :around ((stream dual-channel-tty-gray-stream) &key abort)
   (declare (ignorable abort))
-  (%tcsetattr (fd-of stream) tcsanow (original-settings stream))
-  (foreign-free (original-settings stream))
-  (setf (slot-value stream 'original-settings) nil)
+  (when (fd-of stream)
+    (%tcsetattr (fd-of stream) tcsanow (original-settings stream))
+    (foreign-free (original-settings stream))
+    (setf (slot-value stream 'original-settings) nil))
   (call-next-method))
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defmethod stream-read-sequence :before ((stream dual-channel-tty-gray-stream)
ViewGit