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.
FILE *vlc_fopen (const char *filename, const char *mode)
{
int rwflags = 0, oflags = 0;
- bool append = false;
for (const char *ptr = mode; *ptr; ptr++)
{
case 'a':
rwflags = O_WRONLY;
- oflags |= O_CREAT;
- append = true;
+ oflags |= O_CREAT | O_APPEND;
break;
case 'w':
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);