delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/06/18/19:42:52

From: earnie_boyd AT yahoo DOT com (Earnie Boyd)
Subject: fread, fseek and ftell vs. _read and _lseek
18 Jun 1998 19:42:52 -0700 :
Message-ID: <19980618151243.11713.rocketmail.cygnus.gnu-win32@send1c.yahoomail.com>
Reply-To: earnie_boyd AT yahoo DOT com
Mime-Version: 1.0
To: gw32 <gnu-win32 AT cygnus DOT com>

---2131475428-832100416-898182762=:22141
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Based on the documentation from M$ and the sample program I've attached; it is my opinion that fread and fseek should not be used for "text mode" files.  Instead, use _read and _lseek.

With fread when a ^Z is encountered the file pointer is left indeterminate and so is the data it was reading when the EOF error occured.

With _read, the file pointer will be left intact and the data is returned including the ^Z.  You can then use _lseek to seek to the character past the EOF ^Z marker, ( e.g.: _lseek( fh, 1L, SEEK_CUR ); ) and then continue reading.

You will find attached testseek.c and testseek.dat which demonstrate this.
==
-        \\||//
---o0O0--Earnie--0O0o----
--earnie_boyd AT yahoo DOT com--
------ooo0O--O0ooo-------



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

---2131475428-832100416-898182762=:22141
Content-Type: application/x-unknown-content-type-fma000_vim; name="testseek.c"
Content-Transfer-Encoding: base64
Content-Description: testseek.c
Content-Disposition: vi; filename="testseek.c"

I2luY2x1ZGUgPGlvLmg+DQojaW5jbHVkZSA8ZmNudGwuaD4NCiNpbmNsdWRl
IDxzdGRsaWIuaD4NCiNpbmNsdWRlIDxzdGRpby5oPg0KI2luY2x1ZGUgPHN0
cmluZy5oPg0KDQp2b2lkDQptYWluKCB2b2lkICkNCnsNCiAgRklMRSAgKnN0
cmVhbTsNCiAgaW50ICAgZmg7DQogIGludCAgIG51bXJlYWQ7DQogIGxvbmcg
IHBvczsNCiAgY2hhciAgYnVmZmVyWzMwXTsNCg0KICBzdHJzZXQoYnVmZmVy
LCAnXDAnKTsNCiAgc3RyZWF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lYWQ6JWk6JXNcbiIsIG51bXJlYWQsIGJ1ZmZlciApOw0KDQogIHBvcyA9
IF9sc2VlayggZmgsIDFMLCBTRUVLX0NVUiApOw0KDQogIG51bXJlYWQgPSBf
cmVhZCggZmgsIGJ1ZmZlciwgMjIgKTsNCiAgcHJpbnRmKCAiNCkgX3JlYWQ6
JWk6JXNcbiIsIG51bXJlYWQsIGJ1ZmZlciApOw0KDQogIHBvcyA9IF9sc2Vl
ayggZmgsIDBMLCBTRUVLX0NVUiApOw0KICBwcmludGYoICI1KSBfbHNlZWs6
JWxkXG4iLCBwb3MgKTsNCg0KICBwb3MgPSBfbHNlZWsoIGZoLCAwTCwgU0VF
S19FTkQgKTsNCiAgcHJpbnRmKCAiNikgX2xzZWVrOiVsZFxuIiwgcG9zICk7
DQoNCiAgZmNsb3NlKCBzdHJlYW0gKTsNCn0NCg==

---2131475428-832100416-898182762=:22141
Content-Type: application/x-unknown-content-type-txtfile; name="testseek.dat"
Content-Transfer-Encoding: base64
Content-Description: testseek.dat
Content-Disposition: attachment; filename="testseek.dat"

YWFhYWFhYWFhYWFhYWFhYWFhYWEaDQpiYmJiYmJiYmJiYmJiYmJiYmJiYg0K
Y2NjY2NjY2NjY2NjY2NjY2NjY2MNCmRkZGRkZGRkZGRkZGRkZGRkZGRkDQpl
ZWVlZWVlZWVlZWVlZWVlZWVlZQ0KZmZmZmZmZmZmZmZmZmZmZmZmZmYNCmdn
Z2dnZ2dnZ2dnZ2dnZ2dnZ2dnDQpoaGhoaGhoaGhoaGhoaGhoaGhoaA0KaWlp
aWlpaWlpaWlpaWlpaWlpaWkNCmpqampqampqampqampqampqampqDQpra2tr
a2tra2tra2tra2tra2traw0KbGxsbGxsbGxsbGxsbGxsbGxsbGwNCm1tbW1t
bW1tbW1tbW1tbW1tbW1tDQpubm5ubm5ubm5ubm5ubm5ubm5ubg0Kb29vb29v
b29vb29vb29vb29vb28NCnBwcHBwcHBwcHBwcHBwcHBwcHBwDQpxcXFxcXFx
cXFxcXFxcXFxcXFxcQ0KcnJycnJycnJycnJycnJycnJycnINCnNzc3Nzc3Nz
c3Nzc3Nzc3Nzc3NzDQp0dHR0dHR0dHR0dHR0dHR0dHR0dA0KdXV1dXV1dXV1
dXV1dXV1dXV1dXUNCnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2DQp3d3d3d3d3d3d3
d3d3d3d3d3d3dw0KeHh4eHh4eHh4eHh4eHh4eHh4eHgNCnl5eXl5eXl5eXl5
eXl5eXl5eXl5DQp6enp6enp6enp6enp6enp6enp6eg0K

---2131475428-832100416-898182762=:22141--
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019