www.digitalmars.com         C & C++   DMDScript  

D - bug?: File : Stream in phobos

reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
On lines 952-953 in phobos/stream.d, this function is used:

hFile = CreateFileA(toStringz(filename), access, share,
   null, OPEN_EXISTING, 0, null);

This means that if you try to open a file that don't exist, it
crash gracefully with an error. This conflicts with the docs
that says:

"
class File : Stream
This subclass is for file system streams.

this()
this(char[] filename)
this(char[] filename, FileMode mode)
Create the stream with no open file, an open file in read and write mode, or
an open file with explicit file mode. mode, if given, is a combination of
FileMode.In (indicating a file that can be read) and FileMode.Out
(indicating a file that can be written). If the file does not exist, it is
created.
"

I therefore suggest this fix to the above lines of stream.d:

hFile = CreateFileA(toStringz(filename), access, share,
   null, CREATE_ALWAYS, 0, null);

Lars Ivar Igesund
Oct 26 2003
parent reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
Dang. I meant

hFile = CreateFileA(toStringz(filename), access, share,
   null, OPEN_ALWAYS, 0, null);

Lars Ivar Igesund

"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bng5g5$dc4$1 digitaldaemon.com...
 On lines 952-953 in phobos/stream.d, this function is used:

 hFile = CreateFileA(toStringz(filename), access, share,
    null, OPEN_EXISTING, 0, null);

 This means that if you try to open a file that don't exist, it
 crash gracefully with an error. This conflicts with the docs
 that says:

 "
 class File : Stream
 This subclass is for file system streams.

 this()
 this(char[] filename)
 this(char[] filename, FileMode mode)
 Create the stream with no open file, an open file in read and write mode,
or
 an open file with explicit file mode. mode, if given, is a combination of
 FileMode.In (indicating a file that can be read) and FileMode.Out
 (indicating a file that can be written). If the file does not exist, it is
 created.
 "

 I therefore suggest this fix to the above lines of stream.d:

 hFile = CreateFileA(toStringz(filename), access, share,
    null, CREATE_ALWAYS, 0, null);

 Lars Ivar Igesund
Oct 26 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
Awesome can you post a patch ?  Or I can try if you dont have time.

C


"Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
news:bng5im$dip$1 digitaldaemon.com...
 Dang. I meant

 hFile = CreateFileA(toStringz(filename), access, share,
    null, OPEN_ALWAYS, 0, null);

 Lars Ivar Igesund

 "Lars Ivar Igesund" <larsivi stud.ntnu.no> wrote in message
 news:bng5g5$dc4$1 digitaldaemon.com...
 On lines 952-953 in phobos/stream.d, this function is used:

 hFile = CreateFileA(toStringz(filename), access, share,
    null, OPEN_EXISTING, 0, null);

 This means that if you try to open a file that don't exist, it
 crash gracefully with an error. This conflicts with the docs
 that says:

 "
 class File : Stream
 This subclass is for file system streams.

 this()
 this(char[] filename)
 this(char[] filename, FileMode mode)
 Create the stream with no open file, an open file in read and write
mode,
 or
 an open file with explicit file mode. mode, if given, is a combination
of
 FileMode.In (indicating a file that can be read) and FileMode.Out
 (indicating a file that can be written). If the file does not exist, it
is
 created.
 "

 I therefore suggest this fix to the above lines of stream.d:

 hFile = CreateFileA(toStringz(filename), access, share,
    null, CREATE_ALWAYS, 0, null);

 Lars Ivar Igesund
Oct 26 2003