MCPcopy Create free account
hub / github.com/audacity/audacity / fsdirNext

Function fsdirNext

lib-src/sqlite/shell.c:2785–2843  ·  view source on GitHub ↗

** Advance an fsdir_cursor to its next row of output. */

Source from the content-addressed store, hash-verified

2783** Advance an fsdir_cursor to its next row of output.
2784*/
2785static int fsdirNext(sqlite3_vtab_cursor *cur){
2786 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2787 mode_t m = pCur->sStat.st_mode;
2788
2789 pCur->iRowid++;
2790 if( S_ISDIR(m) ){
2791 /* Descend into this directory */
2792 int iNew = pCur->iLvl + 1;
2793 FsdirLevel *pLvl;
2794 if( iNew>=pCur->nLvl ){
2795 int nNew = iNew+1;
2796 sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
2797 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
2798 if( aNew==0 ) return SQLITE_NOMEM;
2799 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
2800 pCur->aLvl = aNew;
2801 pCur->nLvl = nNew;
2802 }
2803 pCur->iLvl = iNew;
2804 pLvl = &pCur->aLvl[iNew];
2805
2806 pLvl->zDir = pCur->zPath;
2807 pCur->zPath = 0;
2808 pLvl->pDir = opendir(pLvl->zDir);
2809 if( pLvl->pDir==0 ){
2810 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
2811 return SQLITE_ERROR;
2812 }
2813 }
2814
2815 while( pCur->iLvl>=0 ){
2816 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
2817 struct dirent *pEntry = readdir(pLvl->pDir);
2818 if( pEntry ){
2819 if( pEntry->d_name[0]=='.' ){
2820 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
2821 if( pEntry->d_name[1]=='\0' ) continue;
2822 }
2823 sqlite3_free(pCur->zPath);
2824 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2825 if( pCur->zPath==0 ) return SQLITE_NOMEM;
2826 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2827 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2828 return SQLITE_ERROR;
2829 }
2830 return SQLITE_OK;
2831 }
2832 closedir(pLvl->pDir);
2833 sqlite3_free(pLvl->zDir);
2834 pLvl->pDir = 0;
2835 pLvl->zDir = 0;
2836 pCur->iLvl--;
2837 }
2838
2839 /* EOF */
2840 sqlite3_free(pCur->zPath);
2841 pCur->zPath = 0;
2842 return SQLITE_OK;

Callers

nothing calls this directly

Calls 5

opendirFunction · 0.85
fsdirSetErrmsgFunction · 0.85
readdirFunction · 0.85
fileLinkStatFunction · 0.85
closedirFunction · 0.85

Tested by

no test coverage detected