delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/08/19/09:29:41

X-Authentication-Warning: smtp3.ihug.com.au: Host p116-tnt4.syd.ihug.com.au [203.173.134.116] claimed to be acceleron
Message-ID: <001301c128b2$21beb2c0$0a02a8c0@acceleron>
From: "Andrew Cottrell" <acottrel AT ihug DOT com DOT au>
To: <djgpp-workers AT delorie DOT com>, "Charles Sandmann" <sandmann AT clio DOT rice DOT edu>
Subject: Fseek on STDIN problem on Win 2K
Date: Sun, 19 Aug 2001 23:23:21 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4807.1700
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700
Reply-To: djgpp-workers AT delorie DOT com

Hi,

Patcvh 2.5.3 crashes on Win 2K due to a problem with STDIN. Patch works fine
if I use the --verbose option. I was trying to apply the latest dosexec.c
patch on Win 2K when I found the probelm.

I am just about to go to bed and thought I should send this now and work on
it tomorrow night. It appears that when I open STDIN as a file and set the
file position to zero it really goes to the third character in the input
stream. The input stream is a file that I pipe in usign the "<". I have
included a sample program below that shows the problem. If the test file is
"1234567890ABCDEF" then the test program reads the "34567" characters on Win
2K, but on Win 98 with the same EXE it reads the "12345" characters.

The example below is based on some code in pch.c arround line 120 from the
Patch source code.

The test file is called test and the command line that I execute is:
    seek <test

Andrew

#include <stdio.h>
#include <sys/stat.h>

#define STDIN_FILENO 0

/* TEST FILE IS 123456789ABCDEF */

int main (void)
{
    int char_counter;
    int c;
    long stdin_pos;
    struct stat st;

    FILE *pfp;


    if (fstat (STDIN_FILENO, &st) != 0)
    {
      printf("Error fstat");
      return(-1);
    }
    if (S_ISREG (st.st_mode) && ((stdin_pos = ftell (stdin)) != -1))
    {
        pfp = stdin;
    }
    else
    {
      printf("Error fstmode");
      return(-1);
    }

    if (!pfp)
        return (-1);

    fseek(pfp,0,SEEK_SET);

    printf("%s %d file pos = %d\n", __FILE__, __LINE__, ftell(pfp));

    for (char_counter=0;char_counter<5;char_counter++)
    {
        c = getc (pfp);
        printf("Count = %02d, char = (%c), line = <%d>, file position=
[%d]\n", char_counter,c,__LINE__,ftell(pfp));
        if (c == EOF)
        {
            return 0;
        }
    }

    if (pfp)
        fclose(pfp);

    return(0);
}

- Raw text -


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