From: Rudi S. <ru...@co...> - 2008-02-20 04:55:15
|
On 20.02.2008, at 09:57, Richard M Kreuter wrote: > Rudi Schlatte writes: >> On 20.02.2008, at 03:47, Richard M Kreuter wrote: >>> >>> >>> (2) When OPEN is called with :IF-EXISTS :APPEND, SB-SIMPLE-STREAMS >>> and >>> FD-STREAMs disagree about whether to open the file with O_APPEND. >>> While I don't know what the right semantics for :APPEND is, I >>> think >>> it's worst of all to have the two streams implementations >>> disagree, >>> so I've got SB-SIMPLE-STREAMS using O_APPEND for the moment. >> >> Are you sure this is the right thing? > > I am not sure what the right thing is, but my point in the cited > paragraph was that whatever the right thing is, doing things > differently > in the different streams implementations is certainly wrong, because > it > means that loading SB-SIMPLE-STREAMS changes the consequences of (OPEN > ... :IF-EXISTS :APPEND). Agreed completely so far. > >> From open(2): >> >> Opening a file with O_APPEND set causes each write on the file >> to be appended to the end. >> >> If I understand that correctly, writing to a file after evaluating >> (file-position filestream :start) would still append to the end, >> whereas the hyperspec says this about :append: >> >> Output operations on the stream destructively modify the >> existing file. The file pointer is initially positioned at >> the end of the file. >> >> I don't think these 2 behaviors are the same. > > That's true, they're not. And ISTM that it would be better to not use > O_APPEND, for various reasons I mention in my writeup. > FWIW, I'd argue that our current behaviour for: * (with-open-file (s "/tmp/foo.txt" :direction :output :if- exists :supersede) (write-string "xxxxxxxx" s)) * (with-open-file (s "/tmp/foo.txt" :direction :output :if- exists :append) (file-position s :start) (write-char #\a s)) is a bug -- namely, the file contents end up being "xxxxxxxxa", not "axxxxxxx". I don't have too many CL implementations installed beside sbcl, but at least a recentish Clozure CL and clisp produce a file with content "axxxxxxx" for that test case, so we're doing something different than other CL implementations. I haven't found any passage in the hyperspec that says something like "If a call to 2-argument file-position succeeds, further stream operations will happen at the new file-position", but having a call to 2-arg file-position succeed and then SILENTLY writing data somewhere else seems utterly bogus to me. > OTOH, > > (a) since we're permitted to deviate from the specification in the > CLHS, and I confess I'm not sure what you mean by that -- > (b) if we want to retain compatibility with the current :APPEND > semantics in FD-STREAMs, > > then we should keep O_APPEND there. In summary, I think we simply have a bug here -- and one that iirc got corrected in Paul Foley's simple-streams impl (and perhaps also in the main cmucl sources, not sure) after I reported it to him. I was lax and too inexperienced to check and correct sbcl's fd-stream behavior; I'm sorry I didn't fix this when I was doing work in that area. Cheers, Rudi |