www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/02/16/12:24:34

Delivered-To: listarch-cygwin AT sourceware DOT cygnus DOT com
Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Date: Tue, 16 Feb 1999 07:25:36 -0500
From: Peter Kabal <kabal AT ECE DOT McGill DOT CA>
Subject: Cygwin B20 - fseek under gcc fails to reposition on text files
To: cygwin AT sourceware DOT cygnus DOT com
Reply-to: kabal AT ECE DOT McGill DOT CA
Message-id: <000401be59a7$74919120$2eae60cf@videotron.ca>
MIME-version: 1.0
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800
X-Priority: 3 (Normal)

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 <stdio.h>
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 AT ECE DOT McGill DOT CA
Dept. Electrical & Computer Eng.
McGill University 

- Raw text -


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