Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: Waldek Hebisch
Subject: EOF is not true on reset empty file
Date: 30 Jan 2005, 02:05:50
Tom Schneider wrote:
> One of my programs, which I have used with many compilers in the past,
> started an odd behavior as soon as I compiled with GPC. I rooted down
> to what the cause was and found this:
>
> EOF is not true on a reset empty file.
>
<snip>
> Is this standard behavior for Pascal? I thought that if you reset
> an file, it would be at eof. Where else could it be?
>
There is a little tricky point here: the standard requires read from
text file to give eoln and a space character before eof. So GPC
runtime adds a newline before eof if original file contained no
newline. That was wrong for empty file. The following patch should
fix the problem (apply it relatively to gpc-20041218/p directory):
--- rts/files.pas.bb 2005-01-30 00:55:45.498296856 +0100
+++ rts/files.pas 2005-01-30 00:55:51.371404008 +0100
@@ -1259,7 +1259,10 @@
end;
procedure ReadBuffer (f: GPC_FDR);
+var WasRead: boolean;
begin
+ WasRead := not f^.Status.Unread;
+ f^.Status.Unread := false;
f^.BufPos := 0;
if f^.ReadFunc <> nil then
begin
@@ -1277,7 +1280,8 @@
it prevents detecting whether there actually is an EOLn in the file. }
if f^.BufSize <> 0 then
f^.Status.LastEOLn := f^.BufPtr^[f^.BufSize - 1] = NewLine
- else if ((RTSOptions and ro_SP_EOLn) <> 0) and f^.Status.Text and not f^.Status.LastEOLn then
+ else if ((RTSOptions and ro_SP_EOLn) <> 0) and f^.Status.Text
+ and not f^.Status.LastEOLn and WasRead then
begin
f^.Status.LastEOLn := True;
f^.BufPtr^[0] := NewLine;
@@ -1716,7 +1720,6 @@
n: SizeType;
begin
if not CheckReadableNotEOF (f) then Exit;
- f^.Status.Unread := False;
f^.Status.Undef := False;
f^.Status.LGet := False;
{ @@ this different treatment is suspicious }
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Frank Heckenbach | EOF is not true on reset empty file | 30 Jan 2005, 17:37:02 |
| Author | Subject | Date |
|---|---|---|
| Tom Schneider | EOF is not true on reset empty file | 27 Jan 2005, 02:26:45 |
Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.
Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.
This page was created by Crystal 0.999 (Linux 2.4.27/i686).