From b8b7b498703bfb1ca42e023a6fe772043295d943 Mon Sep 17 00:00:00 2001
From: rtoy <rtoy>
Date: Fri, 22 Jan 2010 13:28:26 +0000
Subject: [PATCH] Oops.  The string buffer contains characters, so to get the
 correct file position, we need to convert what's left in the buffer into
 octets to figure out how many octets haven't been delivered yet.

---
 code/fd-stream.lisp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/code/fd-stream.lisp b/code/fd-stream.lisp
index 889fa531d..4801912da 100644
--- a/code/fd-stream.lisp
+++ b/code/fd-stream.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.93 2010/01/22 06:14:19 rtoy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.94 2010/01/22 13:28:26 rtoy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -1667,10 +1667,18 @@
 			       (fd-stream-ibuf-head stream)))
 		 #+unicode
 		 (if (fd-stream-string-buffer stream)
-		     (decf posn (- (fd-stream-string-buffer-len stream)
-				   (fd-stream-string-index stream)))
+		     ;; The string buffer contains Lisp characters,
+		     ;; not octets!  To figure out how many octets
+		     ;; have not been already supplied, we need to
+		     ;; convert them back to the encoded format and
+		     ;; count the number of octets.
+		     (decf posn (length
+				 (string-encode (subseq (fd-stream-string-buffer stream)
+							(fd-stream-string-index stream)
+							(fd-stream-string-buffer-len stream))
+						(fd-stream-external-format stream))))
 		     (decf posn (- (fd-stream-ibuf-tail stream)
-			       (fd-stream-ibuf-head stream))))
+				   (fd-stream-ibuf-head stream))))
 		 (when (fd-stream-unread stream) ;;@@
 		   (decf posn))
 		 ;; Divide bytes by element size.
-- 
GitLab