Dear all, ( especially C/C++ coders :-) )

Here is a quick quiz :-)

While I was writing a code to read from a remote filesystem I faced a strange issue and I couldn't explain it or find an answer for it (googled for around an hour, read man pages, /usr/include/stdio.h and /usr/include/libio.h and got nothing)

Remote: remote files mounted using NFS on the local machine.

The thing is like that:

        .
        .
        .
        char acBuffer[BLOCK_SIZE + 1] = {0x0};
        int iFileDescriptor = fileno (pfFileHandler);
        clearerr(pfFileHandler);
        while (!feof(pfFileHandler) && !ferror(pfFileHandler))
        {
                int iRet = fread(acBuffer, sizeof(char), sizeof(acBuffer) - 1, pfFileHandler);
                //int iRet = read (iFileDescriptor, acBuffer, sizeof(acBuffer) - 1);
               printf ("%s\t%d\n", acBuffer, iRet);
        }
        .
        .
        .
In the first case (fread) it returns always 0 and never reaches EOF since the stream pointer never gets updated when trying to access remote files while it works on local files properly. In the second case (read) it works properly locally and remotely.

please try it, think about it and tell me if you have an explanation for it ...

Best regards,
--

Khamis Siksek
http://saksoook.blogspot.com
_______________________________________________
General mailing list
[email protected]
http://mail.jolug.org/mailman/listinfo/general_jolug.org

Reply via email to