Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ILDirEnt *ILReadDir(ILDir *directory)
- {
- #ifdef HAVE_DIRENT_H
- #if 1
- ILDirEnt *result = NULL;
- /* Threadsafe version of readdir() */
- /* Fetch a directory entry */
- if((result = (ILDirEnt *)ILMalloc(256)) == NULL)
- {
- return NULL;
- }
- if(readdir_r(directory->dir, &(result->de), &(result->dptr)) != 0)
- {
- ILFree(result);
- return NULL;
- }
- if(!(result->dptr)) /* yet another terminating condition */
- {
- ILFree(result);
- return NULL;
- }
- GetDirEntryType(directory, result);
- return result;
- #else
- #if 0
- /* Not Threadsafe, so maybe if systems need it, we should rewrite it. */
- struct dirent *result;
- ILDirEnt *allocatedResult = NULL;
- if((result = readdir(directory->dir)) == NULL)
- {
- return NULL;
- }
- /* After we know we HAVE a result, we copy it's contents into our
- * own struct */
- allocatedResult = (ILDirEnt *)ILMalloc(sizeof(ILDirEnt));
- if(allocatedResult != NULL)
- {
- allocatedResult->dptr = &(allocatedResult->de);
- ILMemCpy(&(allocatedResult->de), result, sizeof(struct dirent));
- //#if defined(BROKEN_DIRENT)
- strcpy(allocatedResult->de.d_name, result->d_name);
- //#endif
- GetDirEntryType(directory, allocatedResult);
- }
- return allocatedResult;
- #else
- return NULL;
- #endif
- #endif
- #else
- return NULL;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement