Thanks Richard that is very helpful - I was always planning on using 'append' but this makes more sense now....FourthWorld wrote: ↑Thu Dec 22, 2022 9:11 pmBut there's one subtle distinction that turns out to make it an especially good choice for some log files. This wasn't easy to find; most online discussions of append only describe how to use it, not why it exists. But Linux System Programming by Robert Love, a favorite in my bookshelf, offers the only why explanation I could put my hands on:
Append Mode
When fd is opened in append mode (via O_APPEND), writes do not occur at the file descriptor’s current file position. Instead, they occur at the current end of the file. For example, assume that two processes intend to write to the end of the same file. This is common: consider a log of events shared among many processes. At the start, their file positions are correctly set to the end of the file. The first process writes to the end
of the file. Without append mode, once the second process attempts the same, it will end up writing not to the end of the file, but to the offset that was the end of the file, before the data that the first process wrote. This means that multiple processes can never append to the same file without explicit synchronization between them because they will encounter race conditions. Append mode avoids this problem. It ensures that the file position is always set to the end of the file so all writes always append, even when there are multiple writers. You can think of it as an atomic update to the file position preceding each write request. The file position is then updated to point at the end of the newly written data. This will not matter to the next call to write(), as it updates the file position automatically, but it might matter if you next call read() for some odd reason.
Not sure I agree with that. The dictionary definition is:richmond62 wrote: ↑Thu Dec 22, 2022 11:10 pmSo, while you may characterise my looking up 'append' and nothing further as 'lazy' I would choose to lay the blame
firmly at the door of the dictionary (and, by extension, its authors) who, frankly, did a sloppy job with 'append'.
They give several examples, all of which show filepath, not URL:open file <filePath> [for [ {[<encoding>] text | binary}] {update | read | write | append}]
Code: Select all
open file "temp.txt"
open file "/etc/Glossary" for write
open file (myFilePath & "/" & myFileName) for binary read
Code: Select all
open file filePath for append
S.