tags:

views:

94

answers:

2

I've been looking over the Doom 3 SDK code, specifically their File System implementation.

The system works (the code I have access to at least) by passing around an 'idFile' object and I've noticed that this class provides read and write methods as well as maintaining a FILE* member.

This suggests to me that either the FILE* is 'opened' with read and write access or the file is closed and reopened (with the appropriate access) between calls to Read() and Write().
Does this sound correct or am I over simplifying it?
If this isn't the case (which part of me suspects it isn't - due to speed etc.) does anyone have any suggestions as to how they would achieve this elegant interface?

Please bare in mind that I am fairly new to both C++ and stdio (which I'm pretty sure iD favours).

A: 

Without ever having looked at the Doom code (I'm guessing you can specify a mode when you create the object), you can use freopen() to re-open a file (in a different mode, if you want) without closing it first.

gnud
OK - if I've read that right "Streams originally opened with mode ``r'' can only be reopened with that same mode." you wouldn't be able to write() to a file after its been read() using this approach?
Adam Naylor
+1  A: 

You can open a FILE* in read-write mode.

If you do that, you should flush and seek to a known location when changing between reading and writing, but you don't have to reopen the file.

pjc50