VLC_EXPORT( char *, utf8_readdir, ( DIR *dir ) );
VLC_EXPORT( int, utf8_loaddir, ( DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
VLC_EXPORT( int, utf8_scandir, ( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
-VLC_EXPORT( int, utf8_mkdir, ( const char *filename ) );
+VLC_EXPORT( int, utf8_mkdir, ( const char *filename, mode_t mode ) );
#ifdef WIN32
# define stat _stati64
return i_ret;
}
-#ifndef MAX_PATH
-# define MAX_PATH 250
-#endif
static void ArtCacheCreateDir( const char *psz_dir )
{
- char newdir[MAX_PATH+1];
+ char newdir[strlen( psz_dir ) + 1];
strcpy( newdir, psz_dir );
char * psz_newdir = newdir;
char * psz = psz_newdir;
while( *psz && *psz != DIR_SEP_CHAR) psz++;
if( !*psz ) break;
*psz = 0;
- if( !EMPTY_STR( psz_newdir ) ) utf8_mkdir( psz_newdir );
+ if( !EMPTY_STR( psz_newdir ) )
+ utf8_mkdir( psz_newdir, 0700 );
*psz = DIR_SEP_CHAR;
psz++;
}
- utf8_mkdir( psz_dir );
+ utf8_mkdir( psz_dir, 0700 );
}
static char * ArtCacheGetSanitizedFileName( const char *psz )
char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );
char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );
- snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
+ snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
p_obj->p_libvlc->psz_cachedir,
psz_artist_sanitized, psz_album_sanitized );
else
{
char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
- snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
+ snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "title" DIR_SEP "%s",
p_obj->p_libvlc->psz_cachedir,
psz_title_sanitized );
const char *psz_artist, const char *psz_album,
const char *psz_extension )
{
- char psz_dir[MAX_PATH+1];
+ char psz_dir[PATH_MAX+1];
char * psz_ext;
ArtCacheGetDirPath( p_obj, psz_dir, psz_title, psz_artist, psz_album );
}
else psz_ext = strdup( "" );
- snprintf( psz_filename, MAX_PATH, "file://%s" DIR_SEP "art%s",
+ snprintf( psz_filename, PATH_MAX, "file://%s" DIR_SEP "art%s",
psz_dir, psz_ext );
free( psz_ext );
char *psz_artist;
char *psz_album;
char *psz_title;
- char psz_dirpath[MAX_PATH+1];
- char psz_filepath[MAX_PATH+1];
+ char psz_dirpath[PATH_MAX+1];
+ char psz_filepath[PATH_MAX+1];
char * psz_filename;
DIR * p_dir;
{
if( !strncmp( psz_filename, "art", 3 ) )
{
- snprintf( psz_filepath, MAX_PATH, "file://%s" DIR_SEP "%s",
+ snprintf( psz_filepath, PATH_MAX, "file://%s" DIR_SEP "%s",
psz_dirpath, psz_filename );
input_item_SetArtURL( p_item, psz_filepath );
free( psz_filename );
{
int i_status = VLC_EGENERIC;
stream_t *p_stream;
- char psz_filename[MAX_PATH+1];
+ char psz_filename[PATH_MAX+1];
char *psz_artist = NULL;
char *psz_album = NULL;
char *psz_title = NULL;
char *psz_album = NULL;
char *psz_title = NULL;
char *psz_type = NULL;
- char psz_filename[MAX_PATH+1];
+ char psz_filename[PATH_MAX+1];
FILE *f;
input_attachment_t *p_attachment;
struct stat s;
{
if( !psz_dirname && !*psz_dirname ) return -1;
- if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
+ if( utf8_mkdir( psz_dirname, 0700 ) == 0 )
+ return 0;
+
+ switch( errno )
{
- if( errno == ENOENT )
+ case EEXIST:
+ return 0;
+
+ case ENOENT:
{
/* Let's try to create the parent directory */
- char *psz_parent = strdup( psz_dirname );
- char *psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
+ char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
+ strcpy( psz_parent, psz_dirname );
+
+ psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
if( psz_end && psz_end != psz_parent )
{
*psz_end = '\0';
if( config_CreateDir( p_this, psz_parent ) == 0 )
{
- if( !utf8_mkdir( psz_dirname ) )
- {
- free( psz_parent );
+ if( !utf8_mkdir( psz_dirname, 0755 ) )
return 0;
- }
}
}
- free( psz_parent );
}
- msg_Err( p_this, "could not create %s: %m", psz_dirname );
- return -1;
}
- return 0;
+ msg_Err( p_this, "could not create %s: %m", psz_dirname );
+ return -1;
}
/*****************************************************************************