platform/posix.c
changeset 362 ac8c846a0a66
parent 310 f8bca4a93fd5
child 429 72ca216c756a
equal deleted inserted replaced
361:0f945e89d537 362:ac8c846a0a66
   216 
   216 
   217 
   217 
   218 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   218 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   219                                                   int omitSymLinks)
   219                                                   int omitSymLinks)
   220 {
   220 {
   221     LinkedStringList *retval = NULL;
   221     LinkedStringList *retval = NULL, *p = NULL;
   222     LinkedStringList *l = NULL;
       
   223     LinkedStringList *prev = NULL;
       
   224     DIR *dir;
   222     DIR *dir;
   225     struct dirent *ent;
   223     struct dirent *ent;
   226     int bufsize = 0;
   224     int bufsize = 0;
   227     char *buf = NULL;
   225     char *buf = NULL;
   228     int dlen = 0;
   226     int dlen = 0;
   248         if (buf != NULL)
   246         if (buf != NULL)
   249             free(buf);
   247             free(buf);
   250         BAIL_IF_MACRO(1, strerror(errno), NULL);
   248         BAIL_IF_MACRO(1, strerror(errno), NULL);
   251     } /* if */
   249     } /* if */
   252 
   250 
   253     while (1)
   251     while ((ent = readdir(dir)) != NULL)
   254     {
   252     {
   255         ent = readdir(dir);
       
   256         if (ent == NULL)   /* we're done. */
       
   257             break;
       
   258 
       
   259         if (strcmp(ent->d_name, ".") == 0)
   253         if (strcmp(ent->d_name, ".") == 0)
   260             continue;
   254             continue;
   261 
   255 
   262         if (strcmp(ent->d_name, "..") == 0)
   256         if (strcmp(ent->d_name, "..") == 0)
   263             continue;
   257             continue;
   278             strcpy(buf + dlen, ent->d_name);
   272             strcpy(buf + dlen, ent->d_name);
   279             if (__PHYSFS_platformIsSymLink(buf))
   273             if (__PHYSFS_platformIsSymLink(buf))
   280                 continue;
   274                 continue;
   281         } /* if */
   275         } /* if */
   282 
   276 
   283         l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
   277         retval = __PHYSFS_addToLinkedStringList(retval, &p, ent->d_name, -1);
   284         if (l == NULL)
       
   285             break;
       
   286 
       
   287         l->str = (char *) malloc(strlen(ent->d_name) + 1);
       
   288         if (l->str == NULL)
       
   289         {
       
   290             free(l);
       
   291             break;
       
   292         } /* if */
       
   293 
       
   294         strcpy(l->str, ent->d_name);
       
   295 
       
   296         if (retval == NULL)
       
   297             retval = l;
       
   298         else
       
   299             prev->next = l;
       
   300 
       
   301         prev = l;
       
   302         l->next = NULL;
       
   303     } /* while */
   278     } /* while */
   304 
   279 
   305     if (buf != NULL)
   280     if (buf != NULL)
   306         free(buf);
   281         free(buf);
   307 
   282