Advertisement
Guest User

Untitled

a guest
Feb 12th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. ILDirEnt *ILReadDir(ILDir *directory)
  2. {
  3. #ifdef HAVE_DIRENT_H
  4.  
  5. #if 1
  6.     ILDirEnt *result = NULL;
  7.  
  8.     /* Threadsafe version of readdir() */
  9.     /*  Fetch a directory entry  */
  10.     if((result = (ILDirEnt *)ILMalloc(256)) == NULL)
  11.     {
  12.         return NULL;
  13.     }
  14.  
  15.     if(readdir_r(directory->dir, &(result->de), &(result->dptr)) != 0)
  16.     {
  17.         ILFree(result);
  18.         return NULL;
  19.     }
  20.     if(!(result->dptr)) /* yet another terminating condition */
  21.     {
  22.         ILFree(result);
  23.         return NULL;
  24.     }
  25.  
  26.     GetDirEntryType(directory, result);
  27.     return result;
  28. #else
  29. #if 0
  30.     /*  Not Threadsafe, so maybe if systems need it, we should rewrite it.  */
  31.     struct dirent *result;
  32.     ILDirEnt *allocatedResult = NULL;
  33.     if((result = readdir(directory->dir)) == NULL)
  34.     {
  35.         return NULL;
  36.     }
  37.  
  38.     /*  After we know we HAVE a result, we copy it's contents into our
  39.      *  own struct  */
  40.     allocatedResult = (ILDirEnt *)ILMalloc(sizeof(ILDirEnt));
  41.     if(allocatedResult != NULL)
  42.     {
  43.         allocatedResult->dptr = &(allocatedResult->de);
  44.         ILMemCpy(&(allocatedResult->de), result, sizeof(struct dirent));
  45. //#if defined(BROKEN_DIRENT)
  46.         strcpy(allocatedResult->de.d_name, result->d_name);
  47. //#endif
  48.         GetDirEntryType(directory, allocatedResult);
  49.     }
  50.     return allocatedResult;
  51. #else
  52.     return NULL;
  53. #endif
  54. #endif
  55. #else
  56.     return NULL;
  57. #endif
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement