Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!ptsfa!ihnp4!alberta!sask!lowey From: lowey@sask.UUCP (Kevin Lowey) Newsgroups: comp.sys.ibm.pc,comp.lang.pascal Subject: Bug in Turbo Pascal 3.01a (append) Message-ID: <918@sask.UUCP> Date: Wed, 28-Oct-87 14:21:28 EST Article-I.D.: sask.918 Posted: Wed Oct 28 14:21:28 1987 Date-Received: Wed, 4-Nov-87 06:40:29 EST Organization: University of Saskatchewan Lines: 72 Keywords: pascal, msdos, turbo Xref: mnetor comp.sys.ibm.pc:9579 comp.lang.pascal:435 Hi, I've discovered a bug in Turbo Pascal version 3.01a (PC-DOS). This version has a function called APPEND which is used to open a file at the end of the file, so that you can append information to the end. In version 3.01a of Turbo Pascal, if you try to append to a file of length 0 (an empty file), when Turbo tries to write the first buffer to the file (either with the CLOSE command or a lot of write/writeln commands) you get IO error F0, Disk Write Error. The following program demonstrates this problem: ====================================================== program bug; {Demonstates a bug in Turbo Pascal version 3.01 } {appending to a null file creates an error message } var fil:text; begin {create file of length 0} assign (fil,'test.fil'); rewrite (fil); close (fil); { append to the file } append (fil); write (fil,'Testing, 1,2,3'); close (fil); {<<< IO error F0, "Disk Write Error", occurs here } end. =================================================================== The following program fixes this problem: =================================================================== program fix; {Demonstates fix to bug in Turbo Pascal version 3.01 } {appending to a null file creates an error message } var fil:text; procedure myappend ( var fil:text); begin reset (fil); if EOF(fil) then rewrite(fil) else append (fil); end; begin {create file of length 0} assign (fil,'test.fil'); rewrite (fil); close (fil); { append to the file } myappend (fil); write (fil,'Testing, 1,2,3'); close (fil); end. ======================================================== ______________________________________________________________________________ | Kevin Lowey |The above is the personal opinion of Kevin | | University of Saskatchewan |Lowey. It does not reflect the position of| | Computing Services |the University of Saskatchewan in any way. | | SaskTel: (306) 966-4826 | | | Bitnet:LOWEY@SASK. (preferred) |I am in no way affiliated with any of the | | UUCP: ihnp4!sask!lowey.uucp |above mentioned companies other than U of S| |________________________________|___________________________________________|