Bug using Unix LineFeed

For other topics related to the FreeBASIC project or its community.
Posts: 1492
Joined: Feb 11, 2009 14:24
Location: Austria

Bug using Unix LineFeed

Postby St_W » May 22, 2009 11:41


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
   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
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".
Posts: 3013
Joined: Jan 15, 2007 20:44
Location: Australia

Postby Richard » May 22, 2009 13:33

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

Return to “Community Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests