http://bugs.winehq.org/show_bug.cgi?id=16982
Summary: fgets as first read on file followed by fread gives wrong results Product: Wine Version: 1.0.1 Platform: Other OS/Version: other Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: msvcrt AssignedTo: wine-bugs@winehq.org ReportedBy: lkcl@lkcl.net
Created an attachment (id=18770) --> (http://bugs.winehq.org/attachment.cgi?id=18770) test case
following simple app:
#include <stdio.h>
int main(int argc, char *argv[]) { int i; char buffer[512]; char *buf; FILE *f = fopen("tst", "w"); fwrite("hell\n", 1, 5, f); fwrite("argh\n", 1, 5, f); fwrite("wizz\n", 1, 5, f); fwrite("hell\n", 1, 5, f); fclose(f);
f = fopen("tst", "r");
/*i = fread(buffer, 1, 5, f); printf("buffer: read %d '%s' buffer[4]: %d\n", i, buffer, buffer[4]); */
buf = fgets(buffer, 512, f); printf("fgets: '%s'\n", buf);
i = fread(buffer, 1, 5, f); printf("buffer: read %d buffer[0]: %d '%s' buffer[4]: %d\n", i, buffer[0], buffer, buffer[4]);
printf("filepos: %d\n", ftell(f)); fclose(f); }
with builtin msvcrt:
fgets: 'hell ' buffer: read 4 buffer[0]: 97 'argh^M' buffer[4]: 13 filepos: 11
with native msvcrt.dll: fgets: 'hell ' buffer: read 5 buffer[0]: 97 'argh ' buffer[4]: 10 filepos: 12
where it's going wrong is that it _says_ it's read 4 characters when actually you asked for 5, on the fread(). that, and you get a \r instead of a \n.
also - note the filepos count - in the native run, it _does_ move along on the \r\n so it's not the "number of characters returned" that are counted but it's the "actual position in the real file".
euurrrgh.
http://bugs.winehq.org/show_bug.cgi?id=16982
Dan Kegel dank@kegel.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |dank@kegel.com Status|UNCONFIRMED |ASSIGNED Ever Confirmed|0 |1
--- Comment #1 from Dan Kegel dank@kegel.com 2009-01-17 16:02:35 --- fix coming, see http://www.winehq.org/pipermail/wine-devel/2009-January/072191.html
http://bugs.winehq.org/show_bug.cgi?id=16982
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |testcase
http://bugs.winehq.org/show_bug.cgi?id=16982
--- Comment #2 from Dan Kegel dank@kegel.com 2009-01-18 15:53:25 --- Created an attachment (id=18806) --> (http://bugs.winehq.org/attachment.cgi?id=18806) Proposed fix
Let me know if the attached patch works for you. It passes all tests here, and matches native behavior for me.
http://bugs.winehq.org/show_bug.cgi?id=16982
Dan Kegel dank@kegel.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #18806|0 |1 is obsolete| |
--- Comment #3 from Dan Kegel dank@kegel.com 2009-01-18 16:27:45 --- Created an attachment (id=18809) --> (http://bugs.winehq.org/attachment.cgi?id=18809) Updated, also fixes fgetpos
http://bugs.winehq.org/show_bug.cgi?id=16982
--- Comment #4 from Luke Kenneth Casson Leighton lkcl@lkcl.net 2009-01-19 04:59:18 --- looks good dan
http://bugs.winehq.org/show_bug.cgi?id=16982
Dan Kegel dank@kegel.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED
--- Comment #5 from Dan Kegel dank@kegel.com 2009-01-19 10:37:06 --- patch committed, http://www.winehq.org/pipermail/wine-cvs/2009-January/051987.html
http://bugs.winehq.org/show_bug.cgi?id=16982
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #6 from Alexandre Julliard julliard@winehq.org 2009-01-30 11:05:02 --- Closing bugs fixed in 1.1.14.