Skip to content
Snippets Groups Projects
Commit 055b59f6 authored by toaster's avatar toaster
Browse files

Did some research, discovered implementing rewinddir() was as easy as setting...

Did some research, discovered implementing rewinddir() was as easy as setting a value to zero! Now we don't have to open and close the same folder, but instead just jump back to the beginning.
parent 66f56bbb
Branches
Tags
No related merge requests found
...@@ -256,6 +256,28 @@ readdir (DIR * dirp) ...@@ -256,6 +256,28 @@ readdir (DIR * dirp)
return (struct dirent *) 0; return (struct dirent *) 0;
} }
/*
* rewinddir
*
* Makes the next readdir start from the beginning.
*/
int
rewinddir (DIR * dirp)
{
errno = 0;
/* Check for valid DIR struct. */
if (!dirp)
{
errno = EFAULT;
return -1;
}
dirp->dd_stat = 0;
return 0;
}
/* /*
* closedir * closedir
* *
...@@ -537,12 +559,11 @@ boolean preparefilemenu(boolean samemenu) ...@@ -537,12 +559,11 @@ boolean preparefilemenu(boolean samemenu)
} }
} }
closedir(dirhandle); // I don't know how to go back to the start of the folder without just opening and closing... if there's a way, it doesn't appear to be easily manipulatable
if (!sizedirmenu) if (!sizedirmenu)
{ {
if (tempname) if (tempname)
Z_Free(tempname); Z_Free(tempname);
closedir(dirhandle);
return false; return false;
} }
...@@ -554,9 +575,12 @@ boolean preparefilemenu(boolean samemenu) ...@@ -554,9 +575,12 @@ boolean preparefilemenu(boolean samemenu)
} }
if (!(dirmenu = Z_Realloc(dirmenu, sizedirmenu*sizeof(char *), PU_STATIC, NULL))) if (!(dirmenu = Z_Realloc(dirmenu, sizedirmenu*sizeof(char *), PU_STATIC, NULL)))
{
closedir(dirhandle); // just in case
I_Error("Ran out of memory whilst preparing add-ons menu"); I_Error("Ran out of memory whilst preparing add-ons menu");
}
dirhandle = opendir(menupath); rewinddir(dirhandle);
while ((pos+folderpos) < sizedirmenu) while ((pos+folderpos) < sizedirmenu)
{ {
...@@ -635,7 +659,7 @@ boolean preparefilemenu(boolean samemenu) ...@@ -635,7 +659,7 @@ boolean preparefilemenu(boolean samemenu)
dirmenu[0] = Z_StrDup("\1\5UP..."); dirmenu[0] = Z_StrDup("\1\5UP...");
menupath[menupathindex[menudepthleft]] = 0; menupath[menupathindex[menudepthleft]] = 0;
sizedirmenu = (numfolders+pos); // crash prevention if things change between openings somehow sizedirmenu = (numfolders+pos); // just in case things shrink between opening and rewind
if (tempname) if (tempname)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment