Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-lcc!lll-tis!ames!amdcad!sun!imagen!atari!apratt From: apratt@atari.UUCP (Allan Pratt) Newsgroups: comp.sys.atari.st Subject: Re: read past EOF? Message-ID: <749@atari.UUCP> Date: Fri, 5-Jun-87 13:37:24 EDT Article-I.D.: atari.749 Posted: Fri Jun 5 13:37:24 1987 Date-Received: Wed, 10-Jun-87 03:26:45 EDT References: <1987@ihuxy.ATT.COM> Organization: Atari Corp., Sunnyvale CA Lines: 52 in article <1987@ihuxy.ATT.COM>, nowlin@ihuxy.ATT.COM (Jerry Nowlin) says: > If > there are only 300 bytes in the file and I request 1000 Fread() will return > 301 and the 301st byte is a ^Z. Since ^Z is the EOF character in gemdos It > appears that Fread() is actually reading one character past/into the end of > file and sticking that character at the end of the input buffer. ^Z doesn't mean EOF to GEMDOS: it means EOF to some braindamaged programs. Programs like Mince, for instance. If there is a ^Z at the end of your file, it is considered a character just like any other character to GEMDOS. It's up to the library to interpret ^Z as EOF. There is a remark in the GEMDOS documentation to the effect that "Some applications use ^Z to mark EOF in text files." The intent of this was that you should write your programs to be liberal: when dealing with a text file, don't be surprised to see ^Z, but don't be surprised not to. Personally, I prefer no ^Z, because you already know exactly how many bytes there are in a file. But as far as GEMDOS is concerned, files are untyped: there is no concept of a "text" file versus a "binary file" -- all files are just a collection of bytes. Some history: ^Z came to mean EOF because in CP/M, files were allocated in clusters of multiples of 128 bytes. In the directory entry for a file, there was no indication of *exactly* how many bytes were in the file. This didn't matter for programs (binary files), but it did matter for text files. So ^Z was used as the end-of-text marker in text files. MuShDOS preserved this braindamage, even though it didn't need it because it DOES keep track of EXACTLY how many bytes were written to a file. GEMDOS doesn't even document any special treatment of ^Z, but some programs use it to mark EOF in text files (e.g. Mince). To address Mr. Nowlin's remarks specifically: how do you know there are 300 bytes left in the file? Maybe there were 300 text bytes left and one EOF byte (^Z). Here's one way to find out how many bytes are REALLY left in the file: long bytes_left_in_file(fd) int fd; { long pos = Fseek(0L,fd,1); /* get current offset */ long end = Fseek(0L,fd,2); /* seek to end, get offset */ Fseek(pos,fd,0); /* seek back to pos */ return end-pos; } /----------------------------------------------\ | Opinions expressed above do not necessarily | -- Allan Pratt, Atari Corp. | reflect those of Atari Corp. or anyone else. | ...lll-lcc!atari!apratt \----------------------------------------------/