platform/posix.c
branchstable-1.0
changeset 940 a624957f6288
parent 596 381b6ca0dd85
child 1179 eea580b4e199
--- a/platform/posix.c	Wed Mar 12 21:21:40 2008 +0000
+++ b/platform/posix.c	Thu Apr 03 05:07:35 2008 +0000
@@ -344,13 +344,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 *) malloc(sizeof (int));
     if (retval == NULL)
     {