}
static int
-config_Write (FILE *file, const char *type, const char *desc,
+config_Write (FILE *file, const char *desc, const char *type,
bool comment, const char *name, const char *fmt, ...)
{
va_list ap;
file = config_OpenConfigFile( p_this );
if( file != NULL )
{
- /* look for file size */
- fseek( file, 0L, SEEK_END );
- i_sizebuf = ftell( file );
- fseek( file, 0L, SEEK_SET );
- if( i_sizebuf >= LONG_MAX )
- i_sizebuf = 0;
+ struct stat st;
+
+ /* Some users make vlcrc read-only to prevent changes.
+ * The atomic replacement scheme breaks this "feature",
+ * so we check for read-only by hand. */
+ if (fstat (fileno (file), &st)
+ || !(st.st_mode & S_IWUSR))
+ {
+ msg_Err (p_this, "configuration file is read-only");
+ goto error;
+ }
+ i_sizebuf = ( st.st_size < LONG_MAX ) ? st.st_size : 0;
}
p_bigbuffer = p_index = malloc( i_sizebuf+1 );
#ifndef WIN32
fdatasync (fd); /* Flush from OS */
/* Atomically replace the file... */
- utf8_rename (temporary, permanent);
+ if (utf8_rename (temporary, permanent))
+ utf8_unlink (temporary);
/* (...then synchronize the directory, err, TODO...) */
/* ...and finally close the file */
vlc_mutex_unlock (&lock);
#ifdef WIN32
/* Windows cannot remove open files nor overwrite existing ones */
utf8_unlink (permanent);
- utf8_rename (temporary, permanent);
+ if (utf8_rename (temporary, permanent))
+ utf8_unlink (temporary);
vlc_mutex_unlock (&lock);
#endif