<br><font size=3D2 face=3D"sans-serif">Hi,</font>
<br>
<br><font size=3D2 face=3D"sans-serif">The standard is not particularly cle=
ar on this but here goes:</font>
<br>
<br><font size=3D2 face=3D"sans-serif">If you open a file with "ab&quo=
t; it is available only for writing at the end of the file, no reading.</fo=
nt>
<br><font size=3D2 face=3D"sans-serif">If you open it with "a+b" =
you can read as well and the results are as you expect.</font>
<br>
<br><font size=3D2 face=3D"sans-serif">MS documentation is more clear here:=
</font>
<br>
<br><font size=3D3 face=3D"Times New Roman">The character string mode speci=
fies the type of access requested for the file, as follows: </font>
<br><font size=3D3 face=3D"Times New Roman">"r" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens for reading. If the file =
does not exist or cannot be found, the <b>fopen</b> call fails. </font>
<br><font size=3D3 face=3D"Times New Roman">"w" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens an empty file for writing=
. If the given file exists, its contents are destroyed. </font>
<br><font size=3D3 face=3D"Times New Roman">"a" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens for writing at the end of=
the file (appending) without removing the EOF marker before writing new da=
ta to the file; creates the file first if it doesn't exist. </font>
<br><font size=3D3 face=3D"Times New Roman">"r+" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens for both reading and writ=
ing. (The file must exist.) </font>
<br><font size=3D3 face=3D"Times New Roman">"w+" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens an empty file for both re=
ading and writing. If the given file exists, its contents are destroyed. </=
font>
<br><font size=3D3 face=3D"Times New Roman">"a+" </font>
<br><font size=3D3 face=3D"Times New Roman">Opens for reading and appending=
; the appending operation includes the removal of the EOF marker before new=
data is written to the file and the EOF marker is restored after writing i=
s complete; creates the file first if it doesn't exist. </font>
<p><font size=3D3 face=3D"Times New Roman">When a file is opened with the &=
quot;a" or "a+" access type, all write operations occur at t=
he end of the file. The file pointer can be repositioned using <b>fseek</b>=
, but is always moved back to the end of the file before any write operatio=
n is carried out. Thus, existing data cannot be overwritten. </font>
<p><font size=3D3 face=3D"Times New Roman">The "a" mode does not =
remove the EOF marker before appending to the file. After appending has occ=
urred, the MS-DOS TYPE command only shows data up to the original EOF marke=
r and not any data appended to the file. The "a+" mode does remov=
e the EOF marker before appending to the file. After appending, the MS-DOS =
TYPE command shows all data in the file. The "a+" mode is require=
d for appending to a stream file that is terminated with the CTRL+Z EOF mar=
ker. </font>
<p><font size=3D3 face=3D"Times New Roman">When the "r+", "w=
+", or "a+" access type is specified, both reading and writi=
ng are allowed (the file is said to be open for "update"). However, when yo=
u switch between reading and writing, there must be an intervening <b>fflus=
h</b>, <b>fsetpos</b>, or <b>fseek</b> operation. The current position can =
be specified for the <b>fsetpos</b> or <b>fseek</b> operation, if desired. =
</font>
<p><font size=3D3 face=3D"Times New Roman">In addition to the above values,=
the following characters can be included in mode to specify the translatio=
n mode for newline characters: </font>
<p><font size=3D3 face=3D"Times New Roman">t </font>
<br><font size=3D3 face=3D"Times New Roman">Open in text (translated) mode.=
In this mode, CTRL+Z is interpreted as an end-of-file character on input. =
In files opened for reading/writing with "a+", <b>fopen</b> check=
s for a CTRL+Z at the end of the file and removes it, if possible. This is =
done because using <b>fseek</b> and <b>ftell</b> to move within a file that=
ends with a CTRL+Z, may cause <b>fseek</b> to behave improperly near the e=
nd of the file. </font>
<p><font size=3D3 face=3D"Times New Roman">Also, in text mode, carriage ret=
urn–linefeed combinations are translated into single linefeeds on inp=
ut, and linefeed characters are translated to carriage return–linefee=
d combinations on output. When a Unicode stream-I/O function operates in te=
xt mode (the default), the source or destination stream is assumed to be a =
sequence of multibyte characters. Therefore, the Unicode stream-input funct=
ions convert multibyte characters to wide characters. For the same reason, =
the Unicode stream-output functions convert wide characters to multibyte ch=
aracters. </font>
<p><font size=3D3 face=3D"Times New Roman">b </font>
<br><font size=3D3 face=3D"Times New Roman">Open in binary (untranslated) m=
ode; translations involving carriage-return and linefeed characters are sup=
pressed. </font>
<p><font size=3D3 face=3D"Times New Roman">If t or b is not given in mode, =
the default translation mode is defined by the global variable =5F<b>fmode<=
/b>. If t or b is prefixed to the argument, the function fails and returns =
NULL. </font>
<p><font size=3D3 face=3D"Times New Roman">For more information about using=
text and binary modes in Unicode and multibyte stream-I/O, see Text and Bi=
nary Mode File I/O and Unicode Stream I/O in Text and Binary Modes. </font>
<p><font size=3D3 face=3D"Times New Roman">c </font>
<br><font size=3D3 face=3D"Times New Roman">Enable the commit flag for the =
associated filename so that the contents of the file buffer are written dir=
ectly to disk if either <b>fflush</b> or <b>=5Fflushall</b> is called. </fo=
nt>
<br><font size=3D3 face=3D"Times New Roman">n </font>
<br><font size=3D3 face=3D"Times New Roman">Reset the commit flag for the a=
ssociated filename to "no-commit." This is the default. </font>
<br><font size=3D2 face=3D"sans-serif"><br>
I hope this helps</font>
<br>
<br><font size=3D2 face=3D"sans-serif">-<br>
Roger Wells, P.E.<br>
SAIC<br>
221 Third St<br>
Newport, RI 02840<br>
401-847-4210 (voice)<br>
401-849-1585 (fax)<br>
roger@...>
</font>
<br>
<br>
<br>
<table width=3D100%>
<tr valign=3Dtop>
<td>
<td><font size=3D1 face=3D"sans-serif"><b>mls@...>
<br><font size=3D1 face=3D"sans-serif">Sent by: mingw-users-admin@...=
rceforge.net</font>
<p><font size=3D1 face=3D"sans-serif">06/18/2003 08:41 PM</font>
<br><font size=3D1 face=3D"sans-serif">Please respond to Bernd Becker</font>
<br>
<td><font size=3D1 face=3D"Arial"> </font>
<br><font size=3D1 face=3D"sans-serif"> To: &nbs=
p; mingw-user <mingw-users@...;=
</font>
<br><font size=3D1 face=3D"sans-serif"> cc: &nbs=
p; </font>
<br><font size=3D1 face=3D"sans-serif"> Subject:=
[Mingw-users] fseek with SEEK=5FSET - correctio=
n</font></table>
<br>
<br>
<br><font size=3D2 face=3D"Courier New">Hi,<br>
<br>
sorry for the first e-mail, it wasn't meant to be sent :-P<br>
Here's now the real problem:<br>
after fseek is called, for example, like this:<br>
<br>
file=5Fpointer=3Dfopen(filename,"ab");<br>
fseek(file=5Fpointer,4,SEEK=5FSET);<br>
<br>
bytes written with<br>
<br>
putc(byte=5Fto=5Fbe=5Fwritten,file=5Fpointer);<br>
<br>
are appended instead of written at the current file position.<br>
Is this a known problem under Windows ?<br>
Because compiled with DJGPP it works as expected.<br>
<br>
I'm using MinGW 2.0.0.3, Runtime 3.0 and GCC 3.2.3-20030504-1<br>
<br>
<br>
cu,<br>
-- <br>
Bernd<br>
<br>
<br>
<br>
-------------------------------------------------------<br>
This SF.Net email is sponsored by: INetU<br>
Attention Web Developers & Consultants: Become An INetU Hosting Partner=
.<br>
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!<br>
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php<br>
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F<br>
MinGW-users mailing list<br>
MinGW-users@...>
<br>
You may change your MinGW Account Options or unsubscribe at:<br>
https://lists.sourceforge.net/lists/listinfo/mingw-users<br>
<br>
</font>
<br>
<br>
|