platform/posix.c
changeset 939 684c583cb586
parent 852 9467e96abdf1
child 1074 5ad7902d1ab9
--- a/platform/posix.c	Wed Mar 12 21:42:16 2008 +0000
+++ b/platform/posix.c	Thu Apr 03 05:05:48 2008 +0000
@@ -236,13 +236,26 @@
 
 static void *doOpen(const char *filename, int mode)
 {
+    const int appending = (mode & O_APPEND);
     int fd;
     int *retval;
     errno = 0;
 
+    /* O_APPEND doesn't actually behave as we'd like. */
+    mode &= ~O_APPEND;
+
     fd = open(filename, mode, S_IRUSR | S_IWUSR);
     BAIL_IF_MACRO(fd < 0, strerror(errno), NULL);
 
+    if (appending)
+    {
+        if (lseek(fd, 0, SEEK_END) < 0)
+        {
+            close(fd);
+            BAIL_MACRO(strerror(errno), NULL);
+        } /* if */
+    } /* if */
+
     retval = (int *) allocator.Malloc(sizeof (int));
     if (retval == NULL)
     {