On Fri, Jan 25, 2008 at 05:12:39PM -0800, Andreas Raab wrote:
Colin Putney wrote:
On 25-Jan-08, at 10:38 AM, Andreas Raab wrote:
etc. Is there an easy way to patch the Unix file code to avoid this, e.g., behave like Windows in such that it would disallow opening the same file for multiple writes?
I've been bitten by this as well, but in reverse. Code that works great on Unix is totally broken on Windows because you can't open the same file for writing twice.
Easy to change. In sqWin32FilePrims.c function sqFileOpen() modify:
h = CreateFileW(win32Path, writeFlag ? (GENERIC_READ | GENERIC_WRITE) : GENERIC_READ, writeFlag ? FILE_SHARE_READ : (FILE_SHARE_READ | FILE_SHARE_WRITE), "... etc ..."
to read:
h = CreateFileW(win32Path, writeFlag ? (GENERIC_READ | GENERIC_WRITE) : GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, "... etc ..."
So what's the equivalent change for Unix?
The Unix VM is opening the file with fopen(), which does not provide such a control. However, you could use open() to open a file descriptor with the O_EXCL and O_CREAT flags, then pass that file descriptor to fdopen() to get the (FILE *) handle. I have not tested this, but I think it would do what you are looking for here.
Dave
p.s. The Windows VM uses lower level HANDLE rather than the (FILE *) used on other VMs. It would be interesting to know which approach produces the best overall Squeak performance for applications that do significant file I/O.
vm-dev@lists.squeakfoundation.org