[commit][2949] Fix opening a write-only file, beiung careful not to destroy its contents.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[commit][2949] Fix opening a write-only file, beiung careful not to destroy its contents.

commits-3
 
Revision: 2949
Author:   eliot
Date:     2014-06-06 14:00:43 -0700 (Fri, 06 Jun 2014)
Log Message:
-----------
Fix opening a write-only file, beiung careful not to destroy its contents.
See http://lists.squeakfoundation.org/pipermail/vm-dev/2014-June/015699.html

Modified Paths:
--------------
    trunk/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c

Modified: trunk/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
===================================================================
--- trunk/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c 2014-06-05 23:46:11 UTC (rev 2948)
+++ trunk/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c 2014-06-06 21:00:43 UTC (rev 2949)
@@ -245,6 +245,11 @@
    try opening it in write mode to create a new, empty file.
  */
  setFile(f, fopen(cFileName, "w+b"));
+ /* and if w+b fails, try ab to open a write-only file in append mode,
+   not wb which opens a write-only file but overwrites its contents.
+ */
+ if (getFile(f) == NULL)
+ setFile(f, fopen(cFileName, "ab"));
  if (getFile(f) != NULL) {
     char type[4],creator[4];
  dir_GetMacFileTypeAndCreator(sqFileName, sqFileNameSize, type, creator);