]> git.sesse.net Git - vlc/commitdiff
vlc_fopen: fix append mode
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 3 Nov 2011 17:24:14 +0000 (19:24 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 3 Nov 2011 18:03:19 +0000 (20:03 +0200)
In append mode, all write operations must occur at the end of the file.
Nevertheless the initial read offset is the beginning of the file.

src/text/filesystem.c

index 21d58dde563f6df6be5618dc42a01e6ab1fa925a..2e5f26e6bb2a727ec16f4330765177d41e2d2ecd 100644 (file)
@@ -51,7 +51,6 @@
 FILE *vlc_fopen (const char *filename, const char *mode)
 {
     int rwflags = 0, oflags = 0;
-    bool append = false;
 
     for (const char *ptr = mode; *ptr; ptr++)
     {
@@ -63,8 +62,7 @@ FILE *vlc_fopen (const char *filename, const char *mode)
 
             case 'a':
                 rwflags = O_WRONLY;
-                oflags |= O_CREAT;
-                append = true;
+                oflags |= O_CREAT | O_APPEND;
                 break;
 
             case 'w':
@@ -92,12 +90,6 @@ FILE *vlc_fopen (const char *filename, const char *mode)
     if (fd == -1)
         return NULL;
 
-    if (append && (lseek (fd, 0, SEEK_END) == -1))
-    {
-        close (fd);
-        return NULL;
-    }
-
     FILE *stream = fdopen (fd, mode);
     if (stream == NULL)
         close (fd);