www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.stream.File fix

I rewrote this class to fix the following:

1) open() and constructor will now create the file if the file doesn't exist
and only if mode FileMode.Out is specified.
2) Linux error codes were being returned as sizes instead of being handled.
3) Files are now being shared for read and write on Windows, like fopen().

This attached code is donated to the origional author of stream.d and can
have the same license. I'm going to be fixing up parts of phobos for awhile
now and if the changes aren't added, I'll release my own library.

--
Christopher E. Miller


begin 666 filestream.txt
M8VQA<W, 1FEL93H 4W1R96%M#0I[#0H)<')I=F%T93H-" EV97)S:6]N*%=I
M;C,R*0T*"7L-" D):6UP;W)T('-T9"YC+G=I;F1O=W,N=VEN9&]W<SL-" D)
M8V]N<W0 2$%.1$Q%($Y/7T9)3$4 /2!)3E9!3$E$7TA!3D1,15]604Q513L-
M" E]#0H)=F5R<VEO;BAL:6YU>"D-" E[#0H)"6EM<&]R="!S=&0N8RYL:6YU
M>"YL:6YU>#L-" D)86QI87, :6YT($A!3D1,13L-" D)8V]N<W0 2$%.1$Q%
M($Y/7T9)3$4 /2 M,3L-" E]#0H)2$%.1$Q%(&AF:6QE(#T 3D]?1DE,13L-
M" D-" D-" EP=6)L:6,Z#0H)=&AI<R I#0H)>PT*"7T-" D-" D-" ET:&ES
M*$A!3D1,12!H9FEL92P 1FEL94UO9&4 ;6]D92D-" EI; T*"7L-" D)87-S
M97)T*&UO9&4I.PT*"7T-" EB;V1Y#0H)>PT*"0ET:&ES+FAF:6QE(#T :&9I
M;&4[#0H)"7)E861A8FQE(#T *&UO9&4 )B!&:6QE36]D92Y);BD /R!T<G5E
M(#H 9F%L<V4[#0H)"7=R:71E86)L92 ]("AM;V1E("8 1FEL94UO9&4N3W5T
M*2 _('1R=64 .B!F86QS93L-" E]#0H)#0H)#0H)+R\ 3W!E;B!F;W( <F5A
M9&EN9PT*"71H:7,H8VAA<EM=(&9I;&5N86UE*0T*"7L-" D);W!E;BAF:6QE
M;F%M92P 1FEL94UO9&4N26XI.PT*"7T-" D-" D-" ET:&ES*&-H87);72!F
M:6QE;F%M92P 1FEL94UO9&4 ;6]D92D-" E[#0H)"6]P96XH9FEL96YA;64L
M(&UO9&4I.PT*"7T-" D-" D-" E^=&AI<R I#0H)>PT*"0EC;&]S92 I.PT*
M"7T-" D-" D-" DO+R!/<&5N(&9O<B!R96%D:6YG#0H)=F]I9"!O<&5N*&-H
M87);72!F:6QE;F%M92D-" E[#0H)"6]P96XH9FEL96YA;64L($9I;&5-;V1E
M+DEN*3L-" E]#0H)#0H)#0H)=F]I9"!O<&5N*&-H87);72!F:6QE;F%M92P 
M1FEL94UO9&4 ;6]D92D-" E[#0H)"6-L;W-E*"D[#0H)"0T*"0EV97)S:6]N
M*%=I;C,R*0T*"0E[#0H)"0E$5T]21"!A8V-E<W,[#0H)"0E$5T]21"!F;&%G
M<SL-" D)"6EF*&UO9&4 )B!&:6QE36]D92Y);BD-" D)"7L-" D)"0EI9BAM
M;V1E("8 1FEL94UO9&4N3W5T*2 O+R!I;B]O=70-" D)"0E[#0H)"0D)"7)E
M861A8FQE(#T =W)I=&5A8FQE(#T =')U93L-" D)"0D)86-C97-S(#T 1T5.
M15))0U]214%$('P 1T5.15))0U]74DE413L-" D)"0E]#0H)"0D)96QS92 O
M+R!*=7-T(&EN#0H)"0D)>PT*"0D)"0ER96%D86)L92 ]('1R=64[#0H)"0D)
M"6%C8V5S<R ]($=%3D5224-?4D5!1#L-" D)"0E]#0H)"0D)9FQA9W, /2!/
M4$5.7T5825-424Y'.PT*"0D)?0T*"0D)96QS92!I9BAM;V1E("8 1FEL94UO
M9&4N3W5T*2 O+R!*=7-T(&]U= T*"0D)>PT*"0D)"7=R:71E86)L92 ]('1R
M=64[#0H)"0D)86-C97-S(#T 1T5.15))0U]74DE413L-" D)"0EF;&%G<R ]
M($]014Y?04Q705E3.PT*"0D)?0T*"0D)96QS90T*"0D)>PT*"0D)"6%S<V5R
M=" P*3L-" D)"7T-" D)"0T*"0D)+R\ 06QW87ES('-H87)E(')E860O=W)I
M=&4 ;&E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AR
M;W< ;F5W($]P96Y%<G)O<B B1FEL92 G(B!^(&9I;&5N86UE('X (B< ;F]T
M(&9O=6YD+B(I.PT*"0E]#0H)"7-E96MA8FQE(#T =')U93L-" E]#0H)#0H)
M#0H)+R\ 0W)E871E(&9O<B!W<FET:6YG+ T*"79O:60 8W)E871E*&-H87);
M72!F:6QE;F%M92D-" E[#0H)"6-R96%T92AF:6QE;F%M92P 1FEL94UO9&4N
M3W5T*3L-" E]#0H)#0H)#0H)=F]I9"!C<F5A=&4H8VAA<EM=(&9I;&5N86UE
M+"!&:6QE36]D92!M;V1E*0T*"7L-" D)8VQO<V4H*3L-" D)#0H)"2\O(%)E
M<75I<F4 1FEL94UO9&4N3W5T('1O(&-R96%T92X-" D):68H(2AM;V1E("8 
M1FEL94UO9&4N3W5T*2D-" D)"6=O=&\ 8F%D7V-R96%T93L-" D)#0H)"79E
M<G-I;VXH5VEN,S(I#0H)"7L-" D)"4173U)$(&%C8V5S<SL-" D)"6EF*&UO
M9&4 )B!&:6QE36]D92Y);BD-" D)"7L-" D)"0EI9BAM;V1E("8 1FEL94UO
M9&4N3W5T*2 O+R!I;B]O=70-" D)"0E[#0H)"0D)"7)E861A8FQE(#T =W)I
M=&5A8FQE(#T =')U93L-" D)"0D)86-C97-S(#T 1T5.15))0U]214%$('P 
M1T5.15))0U]74DE413L-" D)"0E]#0H)"0D)96QS92 O+R!*=7-T(&EN#0H)
M"0D)>PT*"0D)"0EA<W-E<G0H,"D[#0H)"0D)?0T*"0D)?0T*"0D)96QS92!I
M9BAM;V1E("8 1FEL94UO9&4N3W5T*2 O+R!*=7-T(&]U= T*"0D)>PT*"0D)
M"7=R:71E86)L92 ]('1R=64[#0H)"0D)86-C97-S(#T 1T5.15))0U]74DE4
M13L-" D)"7T-" D)"65L<V4-" D)"7L-" D)"0EA<W-E<G0H,"D[#0H)"0E]
M#0H)"0D-" D)"2\O($%L=V%Y<R!S:&%R92!R96%D+W=R:71E(&QI:V4 9F]P
M96XH*2X-"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