Mail Archives: djgpp/2002/06/18/03:45:10
From: | "Matthew Mucklo" <mmucklo AT hotmail DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | MSDOS/stat() reporting wrong size
|
Lines: | 42
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 6.00.2600.0000
|
X-MimeOLE: | Produced By Microsoft MimeOLE V6.00.2600.0000
|
Message-ID: | <WtBP8.784$dV5.64766992@newssvr13.news.prodigy.com>
|
NNTP-Posting-Host: | 64.171.25.205
|
X-Complaints-To: | abuse AT prodigy DOT net
|
X-Trace: | newssvr13.news.prodigy.com 1024386038 ST000 64.171.25.205 (Tue, 18 Jun 2002 03:40:38 EDT)
|
NNTP-Posting-Date: | Tue, 18 Jun 2002 03:40:38 EDT
|
Organization: | Prodigy Internet http://www.prodigy.com
|
X-UserInfo1: | SCSYQNONXJUYSWDXBZHDM^P AT VZ\LPCXLLBWLOOAFMAVNDQUBLNTC AT AWZWDXZXQ[K\FFSKCVM AT F_N_DOBWVWG__LG@VVOIPLIGX\\BU_B@\P\PFX\B[APHTWAHDCKJF^NHD[YJAZMCY_CWG[SX\Y]^KC\HSZRWSWKGAY_PC[BQ[BXAS\F\\@DMTLFZFUE@\VL
|
Date: | Tue, 18 Jun 2002 07:40:38 GMT
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello,
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
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");
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?
--Matt
I'm trying to use fread to read the entire contents of a file into a buffer,
however the stat.st_size variable returns an improper size for the file.
Hence when I use fread, it always reads less characters than reported by
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
- Raw text -