mo@LBL-UNIX@sri-unix (08/05/82)
From: mo at LBL-UNIX (Mike O'Dell [system]) Date: 16 Jul 1982 11:17:52-PDT A random user approached me about a potential bug in STDIO when a file is opened "rw" and you try to do "fseeks" on it. This was being used as some kind of temp file for some program. I was just wondering if anyone has seen a similar thing before I go off and read all the code for STDIO. -Mike
ecn-pa.scott (08/05/82)
One B*I*G problem with stdio is that the count in the iobuf structure means different things depending on whether one is reading or writing. I never remember which is which, but in one of them, the count is the the number of free bytes in the buffer, and in the other the count is the number of bytes already used. I.e. BOTH putc and getc decrement the count instead of one incrementing and the other decrementing. I had an application in which I used the same structure to hold some data, and turned it into a file if the data exceeded the size of a buffer. I ended up having to write a kludge that turned a write buffer into a read buffer. So, yes, you do have problems if you're both reading and writing a file and try to do fseeks. The fseek can't really know where it is, because it has no record of what was last done on the file. Scott Deerwester Purdue University Libraries