www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.stream

reply Paolo Invernizzi <arathorn NOSPAM_fastwebnet.it> writes:
Hi all,

What is the best 'D' way for opening a file with std.stream readonly but 
raise an exception and NOT to create it if it does not exists?

---
Paolo Invernizzi
Jul 21 2004
parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <cdlkh2$2jn2$1 digitaldaemon.com>, Paolo Invernizzi says...
Hi all,

What is the best 'D' way for opening a file with std.stream readonly but 
raise an exception and NOT to create it if it does not exists?
I don't know of any way of doing this /atomically/ on Windows. (It might work on Linux - can't say as I don't use it). This is a bug which has been mentioned before on this forum, but so far no-one's said anything about fixing it. (Possibly because this is not the bugs forum). My workaround - don't use std.stream unless you KNOW the file already exists. Good old fopen() will do the job just fine - OK, so it's not OO and doesn't throw exceptions and so on, but hopefully it's just a temporary workaround until someone in Phobos realizes that READ access should not CREATE, and does something about it. Arcane Jill
Jul 21 2004
next sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
see my reply to the bug report on digitalmars.d.bugs for the fix to phobos.

"Arcane Jill" <Arcane_member pathlink.com> wrote in message
news:cdllva$2khp$1 digitaldaemon.com...
 In article <cdlkh2$2jn2$1 digitaldaemon.com>, Paolo Invernizzi says...
Hi all,

What is the best 'D' way for opening a file with std.stream readonly but
raise an exception and NOT to create it if it does not exists?
I don't know of any way of doing this /atomically/ on Windows. (It might
work on
 Linux - can't say as I don't use it).

 This is a bug which has been mentioned before on this forum, but so far
no-one's
 said anything about fixing it. (Possibly because this is not the bugs
forum).
 My workaround - don't use std.stream unless you KNOW the file already
exists.
 Good old fopen() will do the job just fine - OK, so it's not OO and
doesn't
 throw exceptions and so on, but hopefully it's just a temporary workaround
until
 someone in Phobos realizes that READ access should not CREATE, and does
 something about it.

 Arcane Jill
Jul 21 2004
prev sibling next sibling parent Sean Kelly <sean f4.ca> writes:
Arcane Jill wrote:
 In article <cdlkh2$2jn2$1 digitaldaemon.com>, Paolo Invernizzi says...
 
Hi all,

What is the best 'D' way for opening a file with std.stream readonly but 
raise an exception and NOT to create it if it does not exists?
I don't know of any way of doing this /atomically/ on Windows. (It might work on Linux - can't say as I don't use it). This is a bug which has been mentioned before on this forum, but so far no-one's said anything about fixing it. (Possibly because this is not the bugs forum).
There is a way to fix this. In fact I've already fixed it in my (much delayed) stream updates. I'm still bogged down with readf but when that's done I'll finish up the stream stuff. Sean
Jul 21 2004
prev sibling parent Paolo Invernizzi <arathorn NOSPAM_fastwebnet.it> writes:
Arcane Jill wrote:

 This is a bug which has been mentioned before on this forum, but so far
no-one's
 said anything about fixing it. (Possibly because this is not the bugs forum).
I was no sure it was a bug ;-)
 My workaround - don't use std.stream unless you KNOW the file already exists.
 Good old fopen() will do the job just fine - OK, so it's not OO and doesn't
 throw exceptions and so on, but hopefully it's just a temporary workaround
until
 someone in Phobos realizes that READ access should not CREATE, and does
 something about it.
Ok... --- Paolo Invernizzi
Jul 21 2004