diff options
author | Oz Linden <oz@lindenlab.com> | 2011-01-17 10:39:54 -0500 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2011-01-17 10:39:54 -0500 |
commit | 7f58b4f2928f60f0a93f49c0897f84af3ea8a78b (patch) | |
tree | ed64dc5178900cb9d31ecc47887fce7755962e7c /indra/llvfs/lldir_linux.cpp | |
parent | dee9c80862ed54138889de8095087dda340ac073 (diff) | |
parent | 74fdba829574e5132fec6633b0ddcd2feb9fe51e (diff) |
merge changes for vwr-24401
Diffstat (limited to 'indra/llvfs/lldir_linux.cpp')
-rw-r--r-- | indra/llvfs/lldir_linux.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/indra/llvfs/lldir_linux.cpp b/indra/llvfs/lldir_linux.cpp index 4ba2f519b0..73f2336f94 100644 --- a/indra/llvfs/lldir_linux.cpp +++ b/indra/llvfs/lldir_linux.cpp @@ -242,6 +242,68 @@ U32 LLDir_Linux::countFilesInDir(const std::string &dirname, const std::string & return (file_count); } +// get the next file in the directory +BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) +{ + glob_t g; + BOOL result = FALSE; + fname = ""; + + if(!(dirname == mCurrentDir)) + { + // different dir specified, close old search + mCurrentDirIndex = -1; + mCurrentDirCount = -1; + mCurrentDir = dirname; + } + + std::string tmp_str; + tmp_str = dirname; + tmp_str += mask; + + if(glob(tmp_str.c_str(), GLOB_NOSORT, NULL, &g) == 0) + { + if(g.gl_pathc > 0) + { + if((int)g.gl_pathc != mCurrentDirCount) + { + // Number of matches has changed since the last search, meaning a file has been added or deleted. + // Reset the index. + mCurrentDirIndex = -1; + mCurrentDirCount = g.gl_pathc; + } + + mCurrentDirIndex++; + + if(mCurrentDirIndex < (int)g.gl_pathc) + { +// llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl; + + // The API wants just the filename, not the full path. + //fname = g.gl_pathv[mCurrentDirIndex]; + + char *s = strrchr(g.gl_pathv[mCurrentDirIndex], '/'); + + if(s == NULL) + s = g.gl_pathv[mCurrentDirIndex]; + else if(s[0] == '/') + s++; + + fname = s; + + result = TRUE; + } + } + + globfree(&g); + } + + return(result); +} + + + + std::string LLDir_Linux::getCurPath() { char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */ |