www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/06/18/05:05:00

From: eplmst AT lu DOT erisoft DOT se (Martin Stromberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: MSDOS/stat() reporting wrong size
Date: 18 Jun 2002 07:51:17 GMT
Organization: Ericsson Erisoft AB, Sweden
Lines: 39
Message-ID: <aemopl$qcm$2@antares.lu.erisoft.se>
References: <WtBP8.784$dV5 DOT 64766992 AT newssvr13 DOT news DOT prodigy DOT com>
NNTP-Posting-Host: lws256.lu.erisoft.se
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


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