Steel Bank Common Lisp

file-position returns zero for file opened for append

Reported by Dave Adam on 2010-04-12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Medium
Unassigned

Bug Description

The following test case should work with any file. This is the first test case I grabbed.

(with-open-file (stream "INSTALL" :direction :output :if-exists :append)
     (values (file-position stream) (file-length stream )))
0
5567

In case it helps, the really confusing part is that it corrects itself after a few writes. The few I just checked corrected file-position after 18 - 44 writes. Then for the next few hundred it was correct.

Version: SBCL 1.0.37

uname -a
Darwin Macintosh.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386

However, this bug was first discovered on Linux.

*features*
(:EXTRA-SAFETY :RESUME-DEBUG :NEW :SANE-EXTERNALS :ALPHACET-THREADS :CL-FAD
 :DANGEROUS :ASDF :SB-THREAD :ANSI-CL :COMMON-LISP :SBCL :SB-DOC :SB-TEST
 :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL :SB-SOURCE-LOCATIONS
 :IEEE-FLOATING-POINT :X86-64 :INODE64 :UNIX :MACH-O :BSD :DARWIN
 :MACH-EXCEPTION-HANDLER :SB-LUTEX :UD2-BREAKPOINTS :GENCGC
 :STACK-GROWS-DOWNWARD-NOT-UPWARD :C-STACK-IS-CONTROL-STACK :LINKAGE-TABLE
 :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP :RAW-INSTANCE-INIT-VOPS
 :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :COMPLEX-FLOAT-VOPS :FLOAT-EQL-VOPS :INLINE-CONSTANTS
 :OS-PROVIDES-DLOPEN :OS-PROVIDES-DLADDR :OS-PROVIDES-PUTWC
 :OS-PROVIDES-BLKSIZE-T :OS-PROVIDES-SUSECONDS-T)

Changed in sbcl:
status: New → Triaged
importance: Undecided → Medium

The attached patch fixes this bug.

This can also be pulled from https://github.com/whalliburton/sbcl

Nikodemus Siivola (nikodemus) wrote :

William, when adding a patch, it's a good idea to also add a "review" tag.

tags: added: review
Changed in sbcl:
assignee: nobody → Nikodemus Siivola (nikodemus)
status: Triaged → In Progress
Changed in sbcl:
assignee: Nikodemus Siivola (nikodemus) → nobody
status: In Progress → Fix Committed
Nikodemus Siivola (nikodemus) wrote :

commit b021c15b8d8e4ea4740323eaee9535c4e7cb2232
Author: William Halliburton <email address hidden>
Date: Sun Feb 13 12:01:17 2011 -0700

    fix initial FILE-POSITION for OPEN :IF-EXISTS :APPEND

      For O_APPEND opened files, lseek returns 0 until first write.
      So we jump ahead initially.

      lp#561642

Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers