Skip to content

tinydir_open_sorted returns -1 in MSVC 2005 #81

Description

@tretdm

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:

SCR_20240610_215048_vmware

MSVC2019 - x64 build:

изображение

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions