TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Kurt Kuzba
from: George White
date: 1998-08-31 20:02:08
subject: 100% (?) ANSI/ISO-compli

Hi Kurt,

As I've just noted to Simon Avery:

 Tom's code:
KK>   That could be done much faster in most cases with fread()
KK>   and a good sized buffer, couldn't it? It would greatly
KK>   reduce the number of iterations necessary. It would still
KK>   be ANSI standard, as far as I can see. ??
KK>long File_len(char *fname)
KK>{
KK>   long file_size = 0, block_read;
KK>   char *buf;
KK>   FILE *fp;
KK>   fp = fopen(fname, "rb");
KK>   if(NULL = fp)
KK>      return -1L;
KK>   buf = malloc(16384);
KK>   if(NULL = buf)
KK>   {
KK>      fclose(fp);
KK>      return -2L;
KK>   }
KK>   do {
KK>      file_size += (block_read = fread(buf, 16384, 1, fp));
...............................................^^^^^^^^
KK>   }  while(block_read > 0);
KK>   free(buf);
KK>   fclose(fp);
KK>   return file_size;
KK>}

You've got the parameters for block size and number of blocks
interchanged. What you've posted will give you the number of complete
blocks of 16384 bytes read, not the file size...

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (2:440/4)
SEEN-BY: 396/1 622/419 632/0 371 633/260 267 270 371 634/397 635/506 728 810
SEEN-BY: 639/252 670/213 218
@PATH: 440/4 255/1 251/25 2320/38 270/101 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.