[vlc-devel] iPaq portablility problem

Jean-Paul Saman jpsaman at wxs.nl
Wed Oct 30 23:52:24 CET 2002


The familiar interface has a routine to read the current directory and 
it displays all files and directories in the user interface. This 
routine is called ReadDirectory. There is a strange problem with this 
routine. I have exhausted all my ideas and am currently running up and 
down a dead alley ;-)

It uses scandir() and that returns a pointer to a char array of struct 
dirent. I'm only interested in the file/directory name and permissions 
of it.
The problem is that scandir() says it found e.g. 5 files/directory but 
when reading namelist[i]->d_name it is an empty string. It is supposed 
to give the name. Why???

When the routine is isolated and run in a seperate program (see 
listdir.c) it works as expected. The file settings.txt includes all 
CFLAGS and LDFLAGS settings used for building vlc.

Here is the routine from familiar_callback.c:

/*****************************************************************
  * Read directory helper function.
  ****************************************************************/
void ReadDirectory( GtkCList *clist, char *psz_dir )
{
     intf_thread_t *p_intf = GtkGetIntf( clist );
     struct dirent **namelist;
     int n=-1;
     int status=-1;

     printf( "Read directory: %s\n", psz_dir );
     if (psz_dir)
     {
        status = chdir(psz_dir);
        if (status<0)
           intf_ErrMsg("File is not a directory.");
     }
     n = scandir(psz_dir, &namelist, 0, NULL);

     printf( "n=%d\n", n);
     if (n<0)
         perror("scandir");
     else
     {
         gchar *ppsz_text[2];
         int i;

         gtk_clist_freeze( p_intf->p_sys->p_clist );
         gtk_clist_clear( p_intf->p_sys->p_clist );
         for (i=0; i<n; i++)
         {
             /* This is a list of strings. */
             ppsz_text[0] = namelist[i]->d_name;
             ppsz_text[1] = get_file_perm(namelist[i]->d_name);
             printf( "Entry: %s, %s\n", namelist[i]->d_name, ppsz_text[1] );
             gtk_clist_insert( p_intf->p_sys->p_clist, i, ppsz_text );
             free(namelist[i]);
         }
         gtk_clist_thaw( p_intf->p_sys->p_clist );
         free(namelist);
     }
}

static char* get_file_perm(const char *path)
{
     struct stat st;
     char *perm;

     perm = (char *) malloc(sizeof(char)*10);
     strncpy( perm, "----------", sizeof("----------"));
     if (lstat(path, &st)==0)
     {
         if (S_ISLNK(st.st_mode))
             perm[0]= 'l';
         else if (S_ISDIR(st.st_mode))
             perm[0]= 'd';
         else if (S_ISCHR(st.st_mode))
             perm[0]= 'c';
         else if (S_ISBLK(st.st_mode))
             perm[0]= 'b';
         else if (S_ISFIFO(st.st_mode))
             perm[0]= 'f';
         else if (S_ISSOCK(st.st_mode))
             perm[0]= 's';
         else if (S_ISREG(st.st_mode))
             perm[0]= '-';
         else /* Unknown type is an error */
             perm[0]= '?';
         /* Get file permissions */
         /* User */
         if (st.st_mode & S_IRUSR)
             perm[1]= 'r';
         if (st.st_mode & S_IWUSR)
             perm[2]= 'w';
         if (st.st_mode & S_IXUSR)
         {
             if (st.st_mode & S_ISUID)
                 perm[3] = 's';
             else
                 perm[3]= 'x';
         }
         else if (st.st_mode & S_ISUID)
             perm[3] = 'S';
         /* Group */
         if (st.st_mode & S_IRGRP)
             perm[4]= 'r';
         if (st.st_mode & S_IWGRP)
             perm[5]= 'w';
         if (st.st_mode & S_IXGRP)
         {
             if (st.st_mode & S_ISGID)
                 perm[6] = 's';
             else
                 perm[6]= 'x';
         }
         else if (st.st_mode & S_ISGID)
             perm[6] = 'S';
         /* Other */
         if (st.st_mode & S_IROTH)
             perm[7]= 'r';
         if (st.st_mode & S_IWOTH)
             perm[8]= 'w';
         if (st.st_mode & S_IXOTH)
         {
             // 'sticky' bit
             if (st.st_mode &S_ISVTX)
                 perm[9] = 't';
             else
                 perm[9]= 'x';
         }
         else if (st.st_mode &S_ISVTX)
             perm[9]= 'T';
     }
     return perm;
}

Does someone spot the mistake? Or give some hints what could be wrong.


Greetings,
Jean-Paul Saman.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: listdir.c
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20021030/55d0a3c8/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: settings.txt
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20021030/55d0a3c8/attachment.txt>


More information about the vlc-devel mailing list