Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::ofstream() problem : not failing on malformed filenames, just not writing anything.

12 views
Skip to first unread message

R.Wieser

unread,
Jan 1, 2013, 8:50:27 AM1/1/13
to
Hello All,

My first steps with VC8 express (Win XP), and I'm compiling a open-source
game called BZFlag.

Somewhere in there here is a

std::ofstream(filename.c_str(), mode);

command, and normally it works well. The the filename is comprized outof a
predefined path (into an existing folder), a name part provided by the user
and a fixed extension.

But users are downright silly beings, not knowing that, for example, a colon
":" is not a valid character in a (windows filesystem) filename. So they
sometimes use them.

The problem is that as a programmer I expected that the "std::ofstream"
function would barf on it so the user could be told to cleanup its filename.
Alas, nothing of the sort.
when I provide a filename like "C:\\foo:bar.tmp" a file named "foo" is
created, but its always zero bytes.

I've tried looking at several status flags (good(), bad() , is_open(), etc),
but none of them seem to, in the above case, indicate anything amiss.

[TL;DR - start reading here]
So, the question is : how does std::ofstream tell me (if at all) that the
above failed and/or how do I detect nothing got written to the file (did
look for but could not find a function (somehow) returning the ammount of
data written into the targetted file).

Regards,
R.Wieser

P.s.
Although I have programming experience, I'm a newbie in regard to "Visual
C++ 2008 Express edition" and the used language therein ...



R.Wieser

unread,
Jan 1, 2013, 3:47:50 PM1/1/13
to
Hello All,

The described problem was located deeper than I thought: I replicated the
behaviour using the basic "CreateFile" function (Kernel32).

The answer ? The "alternate data stream" (ADS), which only works on NTFS
volumes. Its a fully expected behaviour, just not a really known one. :-)

Thanks to Jeroen Mostert for providing me the answer to it (in
comp.os.ms-windows.programmer.win32).

Regards,
Rudy Wieser


-- Origional message:
R.Wieser <add...@not.available> schreef in berichtnieuws
50e2e902$0$6853$e4fe...@news2.news.xs4all.nl...
0 new messages