1. ver. 4.0 FILE I/O BUG
- Posted by bernie Dec 17, 2008
- 1056 views
-- 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)
2. Re: ver. 4.0 FILE I/O BUG
- Posted by jimcbrown (admin) Dec 17, 2008
- 1035 views
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.
-- 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)
3. Re: ver. 4.0 FILE I/O BUG
- Posted by ChrisB (moderator) Dec 17, 2008
- 1001 views
- Last edited Dec 18, 2008
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
4. Re: ver. 4.0 FILE I/O BUG
- Posted by euphoric (admin) Dec 17, 2008
- 1013 views
- Last edited Dec 18, 2008
...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.
5. Re: ver. 4.0 FILE I/O BUG
- Posted by bernie Dec 17, 2008
- 1020 views
- Last edited Dec 18, 2008
...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.
6. Re: ver. 4.0 FILE I/O BUG
- Posted by jimcbrown (admin) Dec 17, 2008
- 990 views
- Last edited Dec 18, 2008
...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.
7. Re: ver. 4.0 FILE I/O BUG
- Posted by DerekParnell (admin) Dec 17, 2008
- 1024 views
- Last edited Dec 18, 2008
-- 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.
8. Re: ver. 4.0 FILE I/O BUG
- Posted by SDPringle Dec 20, 2008
- 999 views
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