diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 02a98b767..79e742919 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -508,28 +508,28 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ - 3); XSTRNCPY(ctx->name + pathLen, "\\*", MAX_FILENAME_SZ - pathLen); - if (!FindFirstRtFile(ctx->name, &ctx->FindFileData, 0)) { + if (!IntimeFindFirst(ctx->name, &ctx->FindFileData)) { WOLFSSL_MSG("FindFirstFile for path verify locations failed"); return BAD_PATH_ERROR; } do { - if (!(ctx->FindFileData.dwFileAttributes & FILE_ATTR_DIRECTORY)) { - dnameLen = (int)XSTRLEN(ctx->FindFileData.cFileName); + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); - if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { - return BAD_PATH_ERROR; - } - XSTRNCPY(ctx->name, path, pathLen + 1); - ctx->name[pathLen] = '\\'; - XSTRNCPY(ctx->name + pathLen + 1, - ctx->FindFileData.cFileName, - MAX_FILENAME_SZ - pathLen - 1); + if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { + return BAD_PATH_ERROR; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '\\'; + XSTRNCPY(ctx->name + pathLen + 1, + IntimeFilename(ctx), + MAX_FILENAME_SZ - pathLen - 1); + if (0 == wc_FileExists(ctx->name)) { if (name) *name = ctx->name; return 0; } - } while (FindNextRtFile(&ctx->FindFileData)); + } while (IntimeFindNext(&ctx->FindFileData)); #elif defined(WOLFSSL_ZEPHYR) if (fs_opendir(&ctx->dir, path) != 0) { @@ -656,18 +656,18 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) } #elif defined(INTIME_RTOS) - while (FindNextRtFile(&ctx->FindFileData)) { - if (!(ctx->FindFileData.dwFileAttributes & FILE_ATTR_DIRECTORY)) { - dnameLen = (int)XSTRLEN(ctx->FindFileData.cFileName); + while (IntimeFindNext(&ctx->FindFileData)) { + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); - if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { - return BAD_PATH_ERROR; - } - XSTRNCPY(ctx->name, path, pathLen + 1); - ctx->name[pathLen] = '\\'; - XSTRNCPY(ctx->name + pathLen + 1, - ctx->FindFileData.cFileName, - MAX_FILENAME_SZ - pathLen - 1); + if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { + return BAD_PATH_ERROR; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '\\'; + XSTRNCPY(ctx->name + pathLen + 1, + IntimeFilename(ctx), + MAX_FILENAME_SZ - pathLen - 1); + if (0 == wc_FileExists(ctx->name)) { if (name) *name = ctx->name; return 0; @@ -758,7 +758,7 @@ void wc_ReadDirClose(ReadDirCtx* ctx) } #elif defined(INTIME_RTOS) - FindRtFileClose(&ctx->FindFileData); + IntimeFindClose(&ctx->FindFileData); #elif defined(WOLFSSL_ZEPHYR) if (ctx->dirp) { diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 291ff4d40..81616e3a7 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -699,6 +699,16 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #define XSTAT _stat #define XS_ISREG(s) (s & _S_IFREG) #define SEPARATOR_CHAR ';' + + #elif defined(INTIME_RTOS) + #include + #define XSTAT _stat64 + #define XS_ISREG(s) S_ISREG(s) + #define SEPARATOR_CHAR ';' + #define XWRITE write + #define XREAD read + #define XCLOSE close + #elif defined(WOLFSSL_ZEPHYR) #define XSTAT fs_stat #define XS_ISREG(s) (s == FS_DIR_ENTRY_FILE) @@ -765,7 +775,12 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); struct M2MB_DIRENT* entry; struct M2MB_STAT s; #elif defined(INTIME_RTOS) - FIND_FILE_DATA FindFileData; + struct stat64 s; + struct _find64 FindFileData; + #define IntimeFindFirst(name, data) (0 == _findfirst64(name, data)) + #define IntimeFindNext(data) (0 == _findnext64(data)) + #define IntimeFindClose(data) (0 == _findclose64(data)) + #define IntimeFilename(ctx) ctx->FindFileData.f_filename #else struct dirent* entry; DIR* dir;