- char *psz_localname = ToLocale( p_access->psz_name );
- char *psz_tmp, *psz_tmp2, *psz_rewriten;
- int fd, i, i_length = strlen( psz_localname );
- for( i = 0, psz_tmp = psz_localname ;
- ( psz_tmp = strstr( psz_tmp, "%T" ) ) ; psz_tmp++, i++ )
- ;
- if( i )
- {
- i_length += 32 * i;
- psz_rewriten = (char *) malloc( i_length );
- if( ! psz_rewriten )
- return ( VLC_EGENERIC );
- psz_tmp = psz_localname;
- psz_tmp2 = psz_rewriten;
- while( *psz_tmp )
- {
- if( ( *psz_tmp == '%' ) && ( *(psz_tmp+1) == 'T' ) )
- {
- time_t t;
- time( &t );
- psz_tmp2 += sprintf( psz_tmp2, "%d", (int) t );
- psz_tmp+=2;
- }
- else
- *psz_tmp2++ = *psz_tmp++;
- }
- *psz_tmp2 = *psz_tmp;
- fd = open( psz_rewriten, i_flags, 0666 );
- LocaleFree( psz_localname );
- free( psz_rewriten );
- }
- else
- {
- fd = open( psz_localname, i_flags, 0666 );
- LocaleFree( psz_localname );
- }
- if( fd == -1 )
- {
- msg_Err( p_access, "cannot open `%s' (%s)", p_access->psz_name,
- strerror( errno ) );
- free( p_access->p_sys );
- return( VLC_EGENERIC );
- }
- p_access->p_sys->i_handle = fd;
+ char *psz_tmp = str_format( p_access, p_access->psz_path );
+ path_sanitize( psz_tmp );
+
+ fd = vlc_open( psz_tmp, O_RDWR | O_CREAT | O_LARGEFILE |
+#ifdef O_SYNC
+ (sync ? O_SYNC : 0) |
+#endif
+ (append ? 0 : O_TRUNC), 0666 );
+ free( psz_tmp );
+ }
+
+ if (fd == -1)
+ {
+ msg_Err( p_access, "cannot open `%s' (%m)", p_access->psz_path );
+ return VLC_EGENERIC;