`tinydir_open_sorted` returns -1 in MSVC 2005
This error occurs when the current directory is opened, the name of which is specified via _getcwd(). It does not appear in MSVC2019.
void FileManager::readCurrentDir() {
char cwd[384];
#ifdef _MSVC
if (_getcwd(cwd, sizeof(cwd)) != NULL) {
#else
if (getcwd(cwd, sizeof(cwd)) != NULL) {
#endif
readDir(cwd);
}
else
gInterface->onError(0, 1);
}
void FileManager::readDir(char* pDirPath) {
int object_index = 0;
tinydir_dir dir;
#ifdef _MSVC
sprintf_s(gCurrentPath, "%s", pDirPath);
#else
sprintf(gCurrentPath, "%s", pDirPath);
#endif
#ifdef _MSVC
if (tinydir_open_sorted(&dir, (TCHAR*)pDirPath) == -1) { // always returns -1 in MSVC 2005
#else
if (tinydir_open_sorted(&dir, pDirPath) == -1) {
#endif
gInterface->onError(0, -1);
return;
}
for (int i = 1; i < dir.n_files; i++) {
if (object_index >= MAX_FILES_COUNT) {
break;
}
tinydir_file file;
if (tinydir_readfile_n(&dir, &file, i) == -1) {
continue;
}
gFiles[object_index] = file;
object_index++;
}
gFilesCount = object_index;
gInterface->onDirectoryRead(gFiles);
tinydir_close(&dir);
}
MSVC2005 - x86 build:
MSVC2019 - x64 build:
What is the value of errno once tinydir_open_sorted fails? Are you able to step through with a debugger and see which line in tinydir_open_sorted it fails on?
What is the value of
errnooncetinydir_open_sortedfails?
The errno value is 2, on some directories either the list is not returned or not completely (showing the first character for each filename in the iterate_sample.c)
I also forgot to clarify that if you use a multibyte character set in MSVC2005, the error does not appear.
iterate_sample uses tinydir_open instead of tinydir_open_sorted. Perhaps it's a different, similar issue?
Also I meant which line in tinydir.h does the error appear.
errono 2 is ENOENT https://learn.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-170 which could be coming from this line https://github.com/cxong/tinydir/blob/a4a2db51af5fd5146eb1d7bcc72610c7bfa28ebb/tinydir.h#L331 It would be good to reproduce this, the exact API call that was made, and why it is returning an error
iterate_sample uses tinydir_open instead of tinydir_open_sorted. Perhaps it's a different, similar issue?
Also I meant which line in tinydir.h does the error appear.
errono 2 is ENOENT https://learn.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-170 which could be coming from this line
https://github.com/cxong/tinydir/blob/a4a2db51af5fd5146eb1d7bcc72610c7bfa28ebb/tinydir.h#L331
It would be good to reproduce this, the exact API call that was made, and why it is returning an error
Yes.