Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!agate!ucbvax!LBL.GOV!forrest From: forrest@LBL.GOV Newsgroups: comp.os.vms Subject: Bug in VAX C Run-Time Library Message-ID: <880126085340.21e04d69@Csa2.LBL.Gov> Date: 26 Jan 88 16:53:40 GMT Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 66 The following program shows a bug in the ftell/fseek routines. I reread the documentation on these routines to make sure what I'm doing is correct and it is. What I'm doing is reading records from a file. If I use ftell to tell me where a certain record is located and then use fseek to go back to the record, I find that the next record differs depending on if the input file is a stream or a variable record file. Note that I am using ftell/fseek at a record boundary, as mentioned in the documentation. --------------------------------------------------- #include stdio #include string char in_line[128]; main() { FILE *ifp; int start_pos; ifp = fopen("testdata","r"); fgets(in_line, sizeof in_line, ifp); /* should read line 1 */ fgets(in_line, sizeof in_line, ifp); /* should read line 2 */ start_pos = ftell(ifp); /* current pos is start of line 3 */ fgets(in_line, sizeof in_line, ifp); /* should read line 3 */ fseek(ifp, start_pos, 0); /* go back to line 3 */ fgets(in_line, sizeof in_line, ifp); /* read unknown line */ printf("Read - %s",in_line); fclose (ifp); } ------------------------------------------------------ Assume the following input file: ------------------------------------------------------- This is line 11111111111111 This is line 222222222222222 This is line 333333333333333 This is line 444444444444444 This is line 555555555555555 ----------------------------- When the input file is a stream record file the program says that it read the third line. But, when the input is a variable record file the programs says it read the second line. I thought that one of the advantages of RMS is that all access methods have the same results even if the record type varies. Even given the requirement that fseek/ftell only work at record boundaries, this program shows that this isn't the case. Furthermore, it means that porting programs from Unix or MS-DOS is made even more difficult. Comments? Jon Forrest FORREST@LBL.GOV (internet) FORREST@LBL (bitnet) -------