Mail Archives: djgpp/2002/06/18/05:05:00
Matthew Mucklo (mmucklo AT hotmail DOT com) wrote:
: I was wondering if anyone knew why MSDOS and stat() therefore return the
: wrong file size. fread() appears to finish ahead of the end of the file as
It doesn't (with 99.9% certainty).
: according to stat(). It's reporting less characters read than are actually
: in the file (yes, the buffer's big enough).
: int main(int argc, char** argv) {
: char buffer[200];
: struct stat fstat;
: FILE *fd;
: int nRead;
: stat(argv[1], &fstat);
: fd = fopen(argv[1], "r");
Try "rb" here,
: if ( (nRead = fread( (void *) buffer, 1, fstat.st_size, fd)) !=
: fstat.st_size ) {
: fprintf( stderr, "Error: not all of file read into buffer, only %d
: characters read\r\n", nRead );
: }
: }
: This cide seems to report an error even when the file size is less than 200.
: Is there some sort of Padding that MSDOS does on files? Is there any logic
: to it?
Yes. DOZE text files have line endings of a pair of 0xa 0xd characters
(not sure about the order). One is removed while reading from files
opened in text mode.
Right,
MartinS
- Raw text -