1. ver. 4.0 FILE I/O BUG

-- This is a example of a program for ver. 4.0 
-- You will find that if a file is open and you try to 
-- open it a second time that OPEN will return a -1 ( fail ). 
-- This does not happen if you use ver. 3.1 
-- If you commment out the include and run the same code 
-- using ver. 3.1; You will see the difference.   
-- 
include std/io.e 
-- 
integer hFile 
-- Create a junk file 
hFile = open("junkfile","w") 
-- Check to see if file open ok. 
if hFile = -1 then puts(1,"junkfile failed to OPEN\n") end if 
-- Write to the open file. 
puts(hFile,"Write some junk to the file\n") 
-- Try to open file again ! 
hFile = open("junkfile","w") 
-- Check to see if file stayed open ! 
if hFile = -1 then 
  puts(1,"junkfile FAILED to STAY OPEN\n") 
else 
  puts(1,"File should still be open\n") 
end if 
-- Pause to for view display. 
if getc(0) then end if 
-- Close the file. 
close(hFile) 
 
new topic     » topic index » view message » categorize

2. Re: ver. 4.0 FILE I/O BUG

This may be related to the 64bit file support in 4.0

Under Linux, I can not reproduce the bug (the file opens fine a second time), so I'm assuming it is a windows specific issue.

bernie said...
-- This is a example of a program for ver. 4.0 
-- You will find that if a file is open and you try to 
-- open it a second time that OPEN will return a -1 ( fail ). 
-- This does not happen if you use ver. 3.1 
-- If you commment out the include and run the same code 
-- using ver. 3.1; You will see the difference.   
-- 
include std/io.e 
-- 
integer hFile 
-- Create a junk file 
hFile = open("junkfile","w") 
-- Check to see if file open ok. 
if hFile = -1 then puts(1,"junkfile failed to OPEN\n") end if 
-- Write to the open file. 
puts(hFile,"Write some junk to the file\n") 
-- Try to open file again ! 
hFile = open("junkfile","w") 
-- Check to see if file stayed open ! 
if hFile = -1 then 
  puts(1,"junkfile FAILED to STAY OPEN\n") 
else 
  puts(1,"File should still be open\n") 
end if 
-- Pause to for view display. 
if getc(0) then end if 
-- Close the file. 
close(hFile) 
 
new topic     » goto parent     » topic index » view message » categorize

3. Re: ver. 4.0 FILE I/O BUG

Hi

Should you be able to open an already opened file a second time, without closing it first? Imagine the case where you opened a file for "r", then opened it for "w" - the file being read would be reset to empty before being written too.

IMHO, trying to open an already open file should return -1

Chris

new topic     » goto parent     » topic index » view message » categorize

4. Re: ver. 4.0 FILE I/O BUG

ChrisB said...

...trying to open an already open file should return -1

I agree, trying to open for write a file that's been already open for writing should be an error. Other programs disallow this behavior as well. If a file is being used by another program, generally you can't mess with it.

new topic     » goto parent     » topic index » view message » categorize

5. Re: ver. 4.0 FILE I/O BUG

euphoric said...
ChrisB said...

...trying to open an already open file should return -1

I agree, trying to open for write a file that's been already open for writing should be an error. Other programs disallow this behavior as well. If a file is being used by another program, generally you can't mess with it.

Thats the way it works on VER 3.1 and Jim said thats the way it works on Linux.

new topic     » goto parent     » topic index » view message » categorize

6. Re: ver. 4.0 FILE I/O BUG

euphoric said...
ChrisB said...

...trying to open an already open file should return -1

I agree, trying to open for write a file that's been already open for writing should be an error. Other programs disallow this behavior as well. If a file is being used by another program, generally you can't mess with it.

Hmm. While there are valid reasons for doing this (such as a records file where we have multiple threads reading a record in one part and writing a record in a later part), it is a very complicated technique to manage well.

The advanced programmer can do this anyways, by bypassing euphoria's builtins and and calling on the OS's API directly.

new topic     » goto parent     » topic index » view message » categorize

7. Re: ver. 4.0 FILE I/O BUG

bernie said...
-- This is a example of a program for ver. 4.0 
-- You will find that if a file is open and you try to 
-- open it a second time that OPEN will return a -1 ( fail ). 
-- This does not happen if you use ver. 3.1 
-- If you commment out the include and run the same code 
-- using ver. 3.1; You will see the difference.   

It sounds to me that the bug in in v3 and not v4. Only one process at a time should have a file open for output.

new topic     » goto parent     » topic index » view message » categorize

8. Re: ver. 4.0 FILE I/O BUG

Maybe it is worth adding to the docs that a file shouldn't be opened a second time before closing the first file handle.

Shawn

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu