Handling streams separately in file-position since fseek doesn't

return the same value as lseek.  Fixes issue #220.
This commit is contained in:
Alex Shinn 2014-05-28 08:01:45 +09:00
parent 719af372f9
commit 72a9782c80
2 changed files with 13 additions and 0 deletions

View file

@ -419,6 +419,8 @@ sexp sexp_seek (sexp ctx, sexp self, sexp x, off_t offset, int whence) {
} }
sexp sexp_tell (sexp ctx, sexp self, sexp x) { sexp sexp_tell (sexp ctx, sexp self, sexp x) {
if (sexp_portp(x) && sexp_stream_portp(x))
return sexp_make_integer(ctx, ftell(sexp_port_stream(x)));
return sexp_seek(ctx, self, x, 0, SEEK_CUR); return sexp_seek(ctx, self, x, 0, SEEK_CUR);
} }

View file

@ -140,4 +140,15 @@
(flush-output out) (flush-output out)
(test 106 sum)) (test 106 sum))
(test "file-position"
'(0 1 2)
(let* ((p (open-input-file "tests/io-tests.scm"))
(t0 (file-position p)))
(read-char p)
(let ((t1 (file-position p)))
(read-char p)
(let ((t2 (file-position p)))
(close-input-port p)
(list t0 t1 t2)))))
(test-end) (test-end)