Just curious if anyone actually will open a file in read/write rather than keep the 2 streams seperate?

Just sees so prone to error have it open to read and write...

  • 6
    You mean writing to a file while something else is also reading from it? That's essentially a FIFO, isn't it? Or some other kind of socket/buffer. They're quite useful actually!
  • 1
    @Condor guess I'm the only person that keeps them seperate then...
  • 7
    If it's inter-process, it can make sense because everything is a file in Unix anyway. One opens for read, the other for write. stdin/out piping is essentially the same. Obviously, you have to take care that reading might yield partial data if the wite access hasn't completed yet.

    Within the same process, it looks pointless, but it can make sense for some temporary data file if you first write, then read. The alternative to close after write and re-open for read offers an interesting potential security hole because the file could be exchanged right in between, which might be a race condition. Coverity Scan raises a warning if you re-open the file by the same path name for exactly that reason.
Your Job Suck?
Get a Better Job
Add Comment