From mboxrd@z Thu Jan 1 00:00:00 1970 From: Earnie Boyd To: kabal@ECE.McGill.CA Cc: cygwin users Subject: Re: Cygwin B20 - fseek under gcc fails to reposition on text files Date: Tue, 16 Feb 1999 05:27:00 -0000 Message-id: <19990216132732.28101.rocketmail@send102.yahoomail.com> X-SW-Source: 1999-02/msg00515.html You need to read the docs about "text mode processing". This is exactly the expected behavior. If you're going to use these functions then you must process in binary mode. Regards, Earnie. ---Peter Kabal wrote: > > Consider a text file (CR/LF line endings). Read a line, save the > current position, seek to end-of-file, seek to the saved position, > read a line. The second read does not return the second line of > the file. > > A shell script which tests the problem is included below: > --------------------------------------------------------------------- > #!/bin/sh > # > # Test fseek bug > # On Cygwin 20.1, a file is not correctly repositioned after seeking to the > # end-of-file on a text file (CR/LF line endings). > > cat > tfrepos.c << EoF > #include > int main (int argc, char *argv[]) > { > FILE *fp; > long int pos, size; > char line[200]; > char *p; > > fp = fopen (argv[1], "r"); > p = fgets (line, 200, fp); > printf (" Line: %s", p); > > pos = ftell (fp); > fseek (fp, 0L, SEEK_END); > fseek (fp, pos, SEEK_SET); > > p = fgets (line, 200, fp); > printf (" Line: %s", p); > > return 0; > } > EoF > > # Run the test program with the c-program as input > gcc tfrepos.c -o tfrepos > ./tfrepos tfrepos.c > > # Clean up > rm -f tfrepos tfrepos.c > --------------------------------------------------------------------- > > Peter Kabal kabal@ECE.McGill.CA > Dept. Electrical & Computer Eng. > McGill University > _________________________________________________________ DO YOU YAHOO!? Get your free @yahoo.com address at http://mail.yahoo.com From mboxrd@z Thu Jan 1 00:00:00 1970 From: Earnie Boyd To: kabal@ECE.McGill.CA Cc: cygwin users Subject: Re: Cygwin B20 - fseek under gcc fails to reposition on text files Date: Sun, 28 Feb 1999 23:02:00 -0000 Message-ID: <19990216132732.28101.rocketmail@send102.yahoomail.com> X-SW-Source: 1999-02n/msg00508.html Message-ID: <19990228230200.O7RYgZRhe9SLLM039FJvjFZU202UJQw9rP9WkhZmeIs@z> You need to read the docs about "text mode processing". This is exactly the expected behavior. If you're going to use these functions then you must process in binary mode. Regards, Earnie. ---Peter Kabal wrote: > > Consider a text file (CR/LF line endings). Read a line, save the > current position, seek to end-of-file, seek to the saved position, > read a line. The second read does not return the second line of > the file. > > A shell script which tests the problem is included below: > --------------------------------------------------------------------- > #!/bin/sh > # > # Test fseek bug > # On Cygwin 20.1, a file is not correctly repositioned after seeking to the > # end-of-file on a text file (CR/LF line endings). > > cat > tfrepos.c << EoF > #include > int main (int argc, char *argv[]) > { > FILE *fp; > long int pos, size; > char line[200]; > char *p; > > fp = fopen (argv[1], "r"); > p = fgets (line, 200, fp); > printf (" Line: %s", p); > > pos = ftell (fp); > fseek (fp, 0L, SEEK_END); > fseek (fp, pos, SEEK_SET); > > p = fgets (line, 200, fp); > printf (" Line: %s", p); > > return 0; > } > EoF > > # Run the test program with the c-program as input > gcc tfrepos.c -o tfrepos > ./tfrepos tfrepos.c > > # Clean up > rm -f tfrepos tfrepos.c > --------------------------------------------------------------------- > > Peter Kabal kabal@ECE.McGill.CA > Dept. Electrical & Computer Eng. > McGill University > _________________________________________________________ DO YOU YAHOO!? Get your free @yahoo.com address at http://mail.yahoo.com