Home
entries friends calendar user info Martin Rydström
prettyclose
Add to Memories
Tell a Friend
OPEN, CLOSE and :SUPERSEDE
The current implementation of (open ... :if-exists :supersede) in CMUCL (and SBCL) is arguably wrong, especially when considering (close ... :abort t).

I suggest we rename the file being opened to a temporary file name, generated by appending (symbol-name (gensym "SUPERSEDED-")) to the file-type (to make the risk of collisions smaller; to be a little more certain, PROBE-FILE it, as well).

Aside from that, what :rename-and-delete currently does is the closest fit that is possible and useful on a regular unix fs, to the best of my knowledge and understanding.

The current behaviour of :supersede (open and truncate) via O_TRUNC is useful, though, so I suggest an extension with the name :truncate (since there is no other way to do that, with just OPEN and standard args).

This is how some different options to OPEN currently work in CMUCL (and, I think, SBCL, except for versions) for "standard streams" (fd-streams):

:if-exists -- note that this is only used if :direction is :io or :output, otherwise ignored

- :error -- Signals an error if the file exists. New, empty file, at position 0.
open() <- O_EXCL

- :new-version -- If the file exists, use the Emacs version stuff; that is, the newest version is "foo.lisp", the first version is "foo.lisp.~1~", and so on. Find the highest- numbered version, and rename the current file to that+1, and create a new file. New, empty file, at position 0.
open() -> O_CREAT

- :rename -- Rename the current file to "filename.BAK", and create a new file. If (close ... :abort t) is called, undo the renaming. If "filename.BAK" exists, overwrite it.
open() <- O_CREAT

- :rename-and-delete -- As above, except after a non-abort CLOSE, delete the renamed file. New, empty file, at position 0.
open () <- O_CREAT

- :overwrite -- Open the current file, at position 0.
No truncation, no open() flags.

- :append -- Open the current file, at file-position end-of-file.
No truncation, no open() flags.

- :supersede -- Open the current file, truncated, at position 0.
open() <- O_TRUNC

- nil -- Return nil. No opening occurs.

---

Note that this behaviour of :if-exists :supersede, which I consider wrong, appears to be the same in the current versions of CMUCL, SBCL, Allegro CL, LispWorks, CLISP, GCL, and ECL on my machine, 2006-12-30.

Tags: ,

profile
prettyclose
Name: prettyclose
calendar
Back January 2007
123456
78910111213
14151617181920
21222324252627
28293031
page summary
tags

Advertisement