TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Simon Avery
from: George White
date: 1998-08-31 19:14:06
subject: 100% (?) ANSI/ISO-compli

Hi Simon,

You wrote to Kurt Kuzba:

SA> KK>    buf = malloc(16384);
SA> KK>       file_size += (block_read = fread(buf, 16384, 1, fp));

SA>Erm, where space for terminating null?

What termiating null?

SA>You're reading in 16384 bytes into a space of 16384, and the terminator's
SA>going to overrun, surely?

As the file was opened in binary mode it will _never_ return more
than the requested number of bytes (obtained by multiplying the unit
size to read by the number of units to read).

A valid criticism of the above code is that it should be:

       file_size += (block_read = fread(buf, 1, 16384, fp));

As written it will give the number of complete reads of 16384 bytes, not
the length of the file.

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™.