Changeset 128cbbabfd57761c125f35d64bae1f8ed83acfc4

Show
Ignore:
Timestamp:
10/11/06 21:56:10 (2 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1163192170 +0000
git-parent:

[69263809ad62332f167463d06cacad2504c47fda]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1163192170 +0000
Message:

Switch the directory to the UTF-8 wrappers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/directory.c

    r07b2e36 r128cbba  
    137137    struct stat stat_info; 
    138138 
    139 #ifdef HAVE_SYS_STAT_H 
     139#ifdef S_ISDIR 
    140140    if (utf8_stat (p_access->psz_path, &stat_info) 
    141141     || !S_ISDIR (stat_info.st_mode)) 
     
    179179static int Read( access_t *p_access, uint8_t *p_buffer, int i_len) 
    180180{ 
    181     char *psz_name = NULL; 
    182181    char *psz; 
    183     char *ptr; 
    184182    int  i_mode, i_activity; 
    185183 
    186     playlist_item_t *p_item, *p_root_category; 
    187     playlist_t *p_playlist = pl_Yield( p_access ); 
    188  
    189     psz_name = ToLocale( p_access->psz_path ); 
    190     ptr = strdup( psz_name ); 
    191     LocaleFree( psz_name ); 
    192     if( ptr == NULL ) 
    193         goto end; 
    194  
    195     psz_name = ptr; 
     184    char *psz_name = strdup (p_access->psz_path); 
     185    if (psz_name == NULL) 
     186        return VLC_ENOMEM; 
    196187 
    197188    /* Remove the ending '/' char */ 
    198     ptr += strlen( ptr ); 
    199     if( ( ptr > psz_name ) ) 
    200     { 
    201         switch( *--ptr
     189    if (psz_name[0]) 
     190    { 
     191        char *ptr = psz_name + strlen (psz_name); 
     192        switch (*--ptr
    202193        { 
    203194            case '/': 
     
    206197        } 
    207198    } 
     199 
     200    playlist_item_t *p_item, *p_root_category; 
     201    playlist_t *p_playlist = pl_Yield( p_access ); 
    208202 
    209203    /* Handle mode */ 
     
    241235                    DIRECTORY_ACTIVITY ); 
    242236 
    243     ReadDir( p_playlist, psz_name , i_mode, p_item, p_root_category ); 
     237    ReadDir( p_playlist, psz_name, i_mode, p_item, p_root_category ); 
    244238 
    245239    i_activity = var_GetInteger( p_playlist, "activity" ); 
    246240    var_SetInteger( p_playlist, "activity", i_activity - 
    247241                    DIRECTORY_ACTIVITY ); 
    248 end: 
    249242    if( psz_name ) free( psz_name ); 
    250243    vlc_object_release( p_playlist ); 
     
    332325} 
    333326 
    334 static int Filter( const struct dirent *foo ) 
    335 
    336     return VLC_TRUE; 
     327 
     328static int Sort (const char **a, const char **b) 
     329
     330    return strcoll (*a, *b); 
    337331} 
    338332 
     
    344338                    playlist_item_t *p_parent_category ) 
    345339{ 
    346     struct dirent   **pp_dir_content = 0
     340    char **pp_dir_content = NULL
    347341    int             i_dir_content, i, i_return = VLC_SUCCESS; 
    348342    playlist_item_t *p_node; 
    349343 
    350     char **ppsz_extensions = 0
     344    char **ppsz_extensions = NULL
    351345    int i_extensions = 0; 
    352346    char *psz_ignore; 
    353347 
    354348    /* Get the first directory entry */ 
    355     i_dir_content = scandir( psz_name, &pp_dir_content, Filter, alphasort ); 
     349    i_dir_content = utf8_scandir (psz_name, &pp_dir_content, NULL, Sort); 
    356350    if( i_dir_content == -1 ) 
    357351    { 
     
    378372        } 
    379373 
    380         ppsz_extensions = (char **)malloc( sizeof( char * ) * i_extensions ); 
     374        ppsz_extensions = (char **)calloc (i_extensions, sizeof (char *)); 
    381375 
    382376        for( a = 0; a < i_extensions; a++ ) 
     
    394388        } 
    395389    } 
     390    if( psz_ignore ) free( psz_ignore ); 
    396391 
    397392    /* While we still have entries in the directory */ 
    398393    for( i = 0; i < i_dir_content; i++ ) 
    399394    { 
    400         struct dirent *p_dir_content = pp_dir_content[i]; 
     395        const char *entry = pp_dir_content[i]; 
    401396        int i_size_entry = strlen( psz_name ) + 
    402                            strlen( p_dir_content->d_name ) + 2; 
    403         char *psz_uri = (char *)malloc( sizeof(char) * i_size_entry )
    404  
    405         sprintf( psz_uri, "%s/%s", psz_name, p_dir_content->d_name ); 
     397                           strlen( entry ) + 2; 
     398        char psz_uri[i_size_entry]
     399 
     400        sprintf( psz_uri, "%s/%s", psz_name, entry); 
    406401 
    407402        /* if it starts with '.' then forget it */ 
    408         if( p_dir_content->d_name[0] != '.'
     403        if (entry[0] != '.'
    409404        { 
    410405#if defined( S_ISDIR ) 
    411406            struct stat stat_data; 
    412407 
    413             if( !stat( psz_uri, &stat_data
     408            if (!utf8_stat (psz_uri, &stat_data
    414409             && S_ISDIR(stat_data.st_mode) && i_mode != MODE_COLLAPSE ) 
    415 #elif defined( DT_DIR ) 
    416             if( ( p_dir_content->d_type & DT_DIR ) && i_mode != MODE_COLLAPSE ) 
    417410#else 
    418411            if( 0 ) 
     
    425418 * in a non-portable way. 
    426419 */ 
    427                 if( lstat( psz_uri, &stat_data
     420                if (utf8_lstat (psz_uri, &stat_data
    428421                 || S_ISLNK(stat_data.st_mode) ) 
    429422                { 
    430423                    msg_Dbg( p_playlist, "skipping directory symlink %s", 
    431424                             psz_uri ); 
    432                     free( psz_uri ); 
    433425                    continue; 
    434426                } 
     
    437429                { 
    438430                    msg_Dbg( p_playlist, "skipping subdirectory %s", psz_uri ); 
    439                     free( psz_uri ); 
    440431                    continue; 
    441432                } 
    442433                else if( i_mode == MODE_EXPAND ) 
    443434                { 
    444                     char *psz_newname, *psz_tmp; 
    445                     msg_Dbg(p_playlist, "reading subdirectory %s", psz_uri ); 
    446  
    447                     psz_tmp = FromLocale( p_dir_content->d_name ); 
    448                     psz_newname = vlc_fix_readdir_charset( 
    449                                                 p_playlist, psz_tmp ); 
    450                     LocaleFree( psz_tmp ); 
    451  
    452                     if( p_parent_category ) 
    453                     { 
    454                         p_node = playlist_NodeCreate( p_playlist, psz_newname, 
    455                                                       p_parent_category ); 
    456                     } 
    457                     else 
    458                     { 
    459                         p_node = playlist_NodeCreate( p_playlist, psz_newname, 
    460                                                       p_parent_category ); 
    461                     } 
    462  
    463                     /* an strdup() just because of Mac OS X */ 
    464                     free( psz_newname ); 
     435                    msg_Dbg(p_playlist, "creading subdirectory %s", psz_uri ); 
     436 
     437                    p_node = playlist_NodeCreate (p_playlist, entry, 
     438                                                  p_parent_category); 
    465439 
    466440                    /* If we had the parent in category, the it is now node. 
     
    478452            { 
    479453                input_item_t *p_input; 
    480                 char *psz_tmp1, *psz_tmp2, *psz_loc; 
    481454 
    482455                if( i_extensions > 0 ) 
    483456                { 
    484                     char *psz_dot = strrchr( p_dir_content->d_name, '.' ); 
     457                    const char *psz_dot = strrchr (entry, '.' ); 
    485458                    if( psz_dot++ && *psz_dot ) 
    486459                    { 
     
    494467                        { 
    495468                            msg_Dbg( p_playlist, "ignoring file %s", psz_uri ); 
    496                             free( psz_uri ); 
    497469                            continue; 
    498470                        } 
     
    500472                } 
    501473 
    502                 psz_loc = FromLocale( psz_uri ); 
    503                 psz_tmp1 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), 
    504                                                     psz_loc ); 
    505                 LocaleFree( psz_loc ); 
    506  
    507                 psz_loc = FromLocale( p_dir_content->d_name ); 
    508                 psz_tmp2 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), 
    509                                                     psz_loc ); 
    510                 LocaleFree( psz_loc ); 
    511  
    512474                p_input = input_ItemNewWithType( VLC_OBJECT(p_playlist), 
    513                                                  psz_tmp1, psz_tmp2, 0, NULL, 
     475                                                 psz_uri, entry, 0, NULL, 
    514476                                                 -1, ITEM_TYPE_VFILE ); 
    515  
    516                 playlist_AddWhereverNeeded( p_playlist, p_input, p_parent, 
    517                                             p_parent_category, VLC_FALSE, 
    518                                             PLAYLIST_APPEND|PLAYLIST_PREPARSE); 
     477                if (p_input != NULL) 
     478                    playlist_AddWhereverNeeded (p_playlist, p_input, p_parent, 
     479                                                p_parent_category, VLC_FALSE, 
     480                                                PLAYLIST_APPEND|PLAYLIST_PREPARSE); 
    519481            } 
    520482        } 
    521         free( psz_uri ); 
    522483    } 
    523484 
     
    526487    if( ppsz_extensions ) free( ppsz_extensions ); 
    527488 
    528     if( psz_ignore ) free( psz_ignore ); 
    529  
    530489    for( i = 0; i < i_dir_content; i++ ) 
    531490        if( pp_dir_content[i] ) free( pp_dir_content[i] );