Interesting. On MS-Windows I get the same results that you got on Solaris, which is correct. That book is wrong. The operating system may read into memory any amount of the file it wants to (buffering), but the file pointer only moves to the location requested in the program. There is little, or no, connection between the operating system's buffer size and the location of the file pointer.
Why the difference on RHEL, I don't know. Maybe there was some other kind of error.
initial file handle :: 0 child read :: abcdefghij child file handle :: 11 parent file handle :: 11 parent read :: lmnopqrstu end file handle :: 22 Press any key to continue . . .
#include<stdio.h>
#include <Windows.h>
FILE* fp = 0;
char buff[11] = {0};
DWORD WINAPI ThreadProc(void* lpParameter)
{
printf("initial file handle :: %d\n",ftell(fp));
fread(buff,sizeof(buff),1,fp);
buff[10]='\0';
printf("child read :: %s\n",buff);
printf("child file handle :: %d\n",ftell(fp));
return 0;
}
int main()
{
fp = fopen("TextFile1.txt", "r");
DWORD dwThreadID = 0;
HANDLE hThread = CreateThread(0,0,ThreadProc,0,0,&dwThreadID);
WaitForSingleObject(hThread,INFINITE);
printf("parent file handle :: %d\n",ftell(fp));
fread(buff,sizeof(buff),1,fp);
buff[10]='\0';
printf("parent read :: %s\n",buff);
printf("end file handle :: %d\n",ftell(fp));
} Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343