APIRET fsChDir(ServerData * pServerData, struct chdir * pchdir) { if (VERIFYFIXED(pchdir->cdfsi.cdi_curdir)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "FS_CHDIR, flag=%d, cdfsi.dir=%s, cdfsi.flags=%d", pchdir->fsFlag, pchdir->cdfsi.cdi_curdir, pchdir->cdfsi.cdi_flags); switch (pchdir->fsFlag) { case CD_EXPLICIT: return changeDir(pServerData, pchdir); case CD_VERIFY: return verifyDir(pServerData, pchdir); case CD_FREE: return freeDir(pServerData, pchdir); default: logMsg(L_EVIL, "unknown FS_CHDIR flag: %d", pchdir->fsFlag); return ERROR_NOT_SUPPORTED; } }
void retrieveDir(char * path) { DIR *pdir; if(path) { chdir(path); getcwd(cwd, FILENAME_MAX); /* Free old directory BEFORE we set numEnt to 0 */ freeDir(); numEnt = 0; scrollY = 0; drgY[1] = drgY[0] = 0; struct dirent *pent; pdir=opendir(cwd); if (pdir) { chdir(cwd); while ((pent=readdir(pdir))!=NULL) { if(strcmp(".", pent->d_name) == 0) continue; if(pent->d_type==DT_REG) { if(isPlayable(pent->d_name)<0) continue; } void * temp = realloc(list, sizeof(char**)*(numEnt+1)); if(temp) { list = temp; int toAlloc = ((strlen(pent->d_name) + sizeof(char)*2)); list[numEnt] = malloc(toAlloc); if(list[numEnt]) { list[numEnt][ENTRY_TYPE] = pent->d_type; strcpy(&list[numEnt][ENTRY_NAME], pent->d_name); numEnt++; } else { freeDir(); closedir(pdir); return; } } } } else { closedir(pdir); return; } if(numEnt == 0) { free(list); list = NULL; } qsort(list, numEnt, sizeof(char*), compare); closedir(pdir); int i; for(i=0; i<numEnt; i++) { if(list[i][ENTRY_TYPE] == DT_REG) break; lastDir = i; } } }