Re: Opening a file for both reading and writing

From: Xavier Leroy (
Date: Thu Feb 18 1999 - 22:06:01 MET

Date: Thu, 18 Feb 1999 22:06:01 +0100
From: Xavier Leroy <>
To: Shin-Cheng Mu <>,
Subject: Re: Opening a file for both reading and writing
In-Reply-To: <>; from Shin-Cheng Mu on Thu, Feb 11, 1999 at 06:00:21PM +0800

> Is it allowed to open a file for both reading and writing?

Yes, but you must be careful about calling flush at the right times.

> I opened the same file for reading and writing in 2 seperate
> channels. Some anomalies happened, e.g. reading from a position
> after overwriting some old data doesn't get the newly written
> value.

Probably you didn't call flush on the output channel to save buffered
writes to the disk file. Just remember to flush each time you switch
from "write" mode to "read" mode, and you should be relatively safe.


- Xavier Leroy

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:20 MET