Conversation

today in "POSIX is a criminal mistake and I hate it personally"

3
0
0

the glibc behavior is the only one that really makes sense anyway

0
0
0

@whitequark things a developer almost definitely wants: a file where reading reads from a different place then where writes go to

2
0
1

@whitequark
I think reading when in append mode does not make sense

I don't know what I would expect tbh

also, since when can the read and the write position be different wtf???

1
0
0

@tthbaltazar in append mode there is no "write position" per se, anything you write gets appended to the end of file regardless of where the file pointer is

3
0
0

@charlotte I went to look up the documentation because this is exactly the behavior I want

0
0
1

@tthbaltazar this is just the semantics of the open(O_APPEND) and write() syscalls

0
0
0

@whitequark @tthbaltazar this makes… some tiny amount of sense for very very specific scenarios

1
0
0

@whitequark @tthbaltazar it can be useful to ask where your write landed after the fact.

1
0
0

@q @whitequark
I can only imagine log style formats, where you want to write from multiple processes

2
0
0

@tthbaltazar @q this is actually fairly common; the fact that the kernel guarantees that every write is appended (and you never overwrite anything) is a very nice guarantee you can't really get otherwise

1
0
0

@tthbaltazar @q @whitequark but wouldn't that result in data races or some other kind of race conditions?

1
0
0

@tanja @tthbaltazar @q not if you use O_APPEND (and respect its limitations)

0
0
0
@whitequark @tthbaltazar @q Does it make any sense in a setup where any `write` can legitimately be partial?
1
0
0

@robryk @tthbaltazar @q sometimes? if you deal with high reliability data storage, filesystems and their guarantees become quite squishy in practice (even for well-documented behaviors...) and you really need to understand exactly what the kernel is doing

1
0
0

@charlotte @whitequark pread() might be sufficient if you keep track of the offset yourself?

Apparently pwrite() also ignores O_APPEND (maybe useful for "write some data and then update a header"?) except on Linux:

"Bugs: POSIX requires that opening a file with the O_APPEND flag should have no affect on the location at which pwrite() writes data. However, on Linux, if a file is opened with O_APPEND, pwrite() appends data to the end of the file, regardless of the value of offset."

0
0
0

@pkhuong @robryk @tthbaltazar @q oh this is very interesting reading—I use COBS heavily in my FPGA work and it's excellent

0
0
0