From 08cdb1c4e4112823eb09876c83bc70d7fa62a888 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Tue, 15 Jul 2008 13:01:55 +0200 Subject: [PATCH] Fix DEVICE-POSITION for files. Signed-off-by: Stelian Ionescu --- io.streams/zeta/device.lisp | 4 +--- io.streams/zeta/file.lisp | 25 +++++++------------------ 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/io.streams/zeta/device.lisp b/io.streams/zeta/device.lisp index a3a6c5d..82e304e 100644 --- a/io.streams/zeta/device.lisp +++ b/io.streams/zeta/device.lisp @@ -15,9 +15,7 @@ (:default-initargs :input-timeout nil :output-timeout nil)) -(defclass single-channel-device (device) - ((position :initarg :position :accessor position-of)) - (:default-initargs :position 0)) +(defclass single-channel-device (device) ()) (defclass dual-channel-device (device) ()) diff --git a/io.streams/zeta/file.lisp b/io.streams/zeta/file.lisp index 2a94271..d30c2b7 100644 --- a/io.streams/zeta/file.lisp +++ b/io.streams/zeta/file.lisp @@ -80,9 +80,7 @@ (let ((fd (try-open))) (%set-fd-nonblock-mode fd t) (setf (input-handle-of device) fd - (output-handle-of device) fd) - (when (logtest flags nix:o-append) - (setf (position-of device) (device-length device))))) + (output-handle-of device) fd))) (values device)) (defun process-file-direction (direction flags if-exists if-does-not-exist) @@ -141,23 +139,14 @@ ;;;----------------------------------------------------------------------------- (defmethod device-position ((device file-device)) - (position-of device)) + (nix:lseek (input-handle-of device) 0 nix:seek-cur)) (defmethod (setf device-position) (position (device file-device) &key (from :start)) - (ecase from - (:start - (nix:lseek (input-handle-of device) position nix:seek-set) - (setf (position-of device) position)) - (:current - (nix:lseek (input-handle-of device) position nix:seek-cur) - (incf (position-of device) position)) - (:end - (nix:lseek (input-handle-of device) position nix:seek-end) - ;; WARNING: possible race condition here: if betweek lseek() and fstat() - ;; the file size is modified, this calculation will be incorrect - ;; perhaps fcntl() or ioctl() can be used to find out the file offset - (setf (position-of device) (+ (device-length device) position)))) - (position-of device)) + (nix:lseek (input-handle-of device) position + (ecase from + (:start nix:seek-set) + (:current nix:seek-cur) + (:end nix:seek-end)))) ;;;----------------------------------------------------------------------------- -- 2.11.4.GIT