Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!motcid!keating From: keating@motcid.UUCP (Edward Keating) Newsgroups: comp.os.msdos.programmer Subject: Re: Turbo C++ fopen() & fflush() Message-ID: <5518@bone34.UUCP> Date: 29 Nov 90 19:05:06 GMT References: <1778@mts.ucs.UAlberta.CA> <1020@marvin.moncam.co.uk> <2493@cod.NOSC.MIL> Organization: Motorola Inc., Cellular Infrastructure Div., Arlington Heights, IL Lines: 26 In article <2493@cod.NOSC.MIL>, bmarsh@cod.NOSC.MIL (William C. Marsh) writes: > > An even easier way to do this is to dup() and then close() the filehandle > associated with the stream. This has worked since version 2.0 of MS-DOS. > You do need an open filehandle to do this, however... > > fflush(stream); > close(dup(fileno(stream))); > This solution will only work for a non-networked version of DOS. It seems that some network implementations (3+) cache the duplicate open and do not flush the information to disk. I had put this identical code into a networked PC environment and then found out that it was non-functional. The most notable problem in this area is that the file length doesn't get written to disk until an the close is performed. The DOS 3.3 and above Flush command is equivalent to an atomic close and re-open that will not allow any other network used to open the file in the window between the close and open. Performing the close and open discretely will flush the information to disk. If you need a lock to prevent others from opening the file, you can use a logical semaphore by using a create file/delete file. i.e. First one to creat a common file name has the resource until he deletes the file. This technique works on a number of different operating systems. -- Ed Keating, Motorola C.I.D, 1501 W. Shure Drive uunet!motcid!keating Arlington Heights, Il 60004 If they revoke the right to assemble, then we can only compile, right?