Bug using Unix LineFeed

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Bug using Unix LineFeed

Post by St_W »

Hi,

I don't know if it's a real bug, so i'd like to get some opinions from you before I submit it to the bugtracker at sourceforge.

Please try and think over the following code:

Code: Select all

'Prepare Bug-Situation
if dir("File.txt")<>"" then kill "File.txt"
open "File.txt" for binary as #1
put #1, 1, "Hello"+chr(10,10)+"World!"
close #1

'Bug in action :-)
dim tmpStr as String

open "File.txt" for input as #1
do
	if eof(1) then exit do
	line input #1, tmpStr
    print ":"+tmpStr
    print lof(1)  '<< ENDLESS LOOP when LOF(1) is called and chr(10, 10) occurs in file
    if inkey = chr(27) then end
    sleep
Loop
close #1
If lof is called an endless loop is the result. If you remove the line with "lof" the program doesn't hang up - it behaves normal.

I think the program shouldn't hang up. Unix LFs are supported by "line input".
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

There is a problem reading from files created on Unix systems that do not have cr-lf. The work around is to always open them in binary mode.
Avoid ‘ Open "File.txt" For Input As #1 , Use ‘ Open "File.txt" For Binary As #1
See http://www.freebasic.net/forum/viewtopic.php?t=8668
Post Reply