Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#117] BinIO.openAppend raises IO on non-existent file

Date:
2013-04-26 21:38
Priority:
3
State:
Closed
Submitted by:
Bug Submitter (webuser)
Assigned to:
Lars Bergstrom (larsberg)
Machine Architecture:
x86
Operating System:
Other
Component:
Basis Library
Resolution:
None
Severity:
Minor
OS Version:
Windows 7
SML/NJ Version:
110.74
Keywords:
URL:
Transcript (of reproduction):
- BinIO.openAppend ile; uncaught exception Io [Io: openAppend failed on ile, win32-bin-prim-io:checkHndl: openApp: failed] raised at: Basis/Implementation/IO/bin-io-fn.sml:623.25-623.75 - BinIO.openOut ile; val it = - : BinIO.outstream - BinIO.closeOut it; val it = () : unit - BinIO.openAppend ile; val it = - : BinIO.outstream
Source (for reproduction):
Summary:
BinIO.openAppend raises IO on non-existent file

Detailed description
When called with a file name that doesn exists, BinIO.openAppend
raises IO. The spec says it is supposed to create the file.
Submitted via web form by Karl Crary crary@cs.cmu.edu

Comments:

Message  ↓
Date: 2013-05-20 17:20
Sender: Lars Bergstrom

OPEN_ALWAYS was the right flag. The position is set immediately after with a second call to setfilepos.

Date: 2013-05-08 12:31
Sender: John Reppy

Looking at the code in Basis/Win32/win32-{text,bin}-prim-io.sml, the problem is obvious. The flag W32IO.OPEN_EXISTING is being used to open the file, but according to the Win32 documentation for createFile, the semantics of this option are

Opens a file or device, only if it exists.
If the specified file or device does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).

The flag OPEN_ALWAYS might work as desired (it is not clear from the documentation if the file pointer is placed at the beginning or end of the file). The other alternative is to check for the file's existence before trying to open it, but that does create a race condition with other processes.

Attached Files:

Changes

Field Old Value Date By
status_idOpen2013-05-20 17:20larsberg
close_date2013-05-20 17:202013-05-20 17:20larsberg
assigned_tonone2013-05-05 16:08jhr