Beyond even closing stdout, the simple case of open(2) a file, write(2) stuff to it, then close(2) it, I have 2 problems:
I have no guarantee that errors will actually be reported in the close(2) call.
When I do have an error, what does it even mean? Should I redo the last write? Oh no I can’t, the documentation says I shouldn’t. Should I close again? Nope, double close is an error as well, even if I got an error. Besides, even if I could, there’s no way to know if the last write completed and the actual error was on close, or if I had a partial write, or something else.
As a careful programmer, my only choice really, when there’s an error on close(2), is to report it back to the user. "Sorry pal, something may or may not have happened with that file we tried to write to, the data in there may or may not be corrupted. Good luck."
Well, unless I’m willing to replay the entire stream of writes to whatever file I just write to. And that’s if it’s not a network connection, or something else where double writes aren’t idempotent.
Goodness, with a design like this, I’m starting to understand the "something unexpected happened" errors from Apple products.
loup-vaillant@reddit
Beyond even closing
stdout
, the simple case ofopen(2)
a file,write(2)
stuff to it, thenclose(2)
it, I have 2 problems:close(2)
call.As a careful programmer, my only choice really, when there’s an error on
close(2)
, is to report it back to the user. "Sorry pal, something may or may not have happened with that file we tried to write to, the data in there may or may not be corrupted. Good luck."Well, unless I’m willing to replay the entire stream of writes to whatever file I just write to. And that’s if it’s not a network connection, or something else where double writes aren’t idempotent.
Goodness, with a design like this, I’m starting to understand the "something unexpected happened" errors from Apple products.