Mail Archives: djgpp-workers/2001/08/19/09:29:41
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 -