views:

194

answers:

1

How can I set the flag FILE_FLAG_BACKUP_SEMANTICS for an fstream object?

You can set most flags with fstream, but it seems like this one is not availble. You can read about the flag here.

+1  A: 

I've done this sort thing in the past but it's been a while so I'm not sure I have it right.

Not well documented, but in vs2008, fstream takes a FILE object as a constructor. You can create a FILE object from a file id with _fdopen(). You can get a file id from an os handle using _open_osfhandle.

So I think it's like:

int id = _open_osfhandle(CreateFile(..., FILE_FLAG_BACKUP_SEMANTICS...));
fstream f = new fstream(_fdopen(id));
Tony Lee
Thanks, really appreciate your help on this.
Brian R. Bondy