--- parser3/src/main/pa_dir.C 2026/09/27 17:21:42 1.38 +++ parser3/src/main/pa_dir.C 2026/10/18 21:05:35 1.42 @@ -5,13 +5,14 @@ Authors: Konstantin Morshnev , Alexandr Petrosian */ -#include "pa_dir.h" #include "pa_common.h" #include "pa_file.h" +#include "pa_dir.h" +#include "pa_os.h" #include "pa_request.h" #include "pa_convert_utf.h" -volatile const char * IDENT_PA_DIR_C="$Id: pa_dir.C,v 1.38 2026/09/27 17:21:42 moko Exp $" IDENT_PA_DIR_H; +volatile const char * IDENT_PA_DIR_C="$Id: pa_dir.C,v 1.42 2026/10/18 21:05:35 moko Exp $" IDENT_PA_DIR_H; #ifdef _MSC_VER @@ -32,12 +33,16 @@ time_t filetime_to_timet(FILETIME const& bool findfirst(const char* _pathname, struct ffblk *_ffblk, int /*_attrib*/) { char mask[MAXPATH]; - snprintf(mask, MAXPATH, "%s/*.*", _pathname); + pa_snprintf(mask, MAXPATH, "%s/*.*", _pathname); const UTF16* utf16mask=pa_utf16_encode(mask, pa_thread_request().charsets.source()); + if(!utf16mask) { // not UTF-8, there can't be such a directory + errno=ENOENT; + return false; + } _ffblk->handle=FindFirstFileW((const wchar_t *)utf16mask, &_ffblk->stat); - return _ffblk->handle==INVALID_HANDLE_VALUE; + return !pa_set_errno(_ffblk->handle!=INVALID_HANDLE_VALUE); // errno as opendir sets it } bool findnext(struct ffblk *_ffblk) { @@ -107,7 +112,7 @@ void findclose(struct ffblk *_ffblk) { void ffblk::stat_file() { char fileSpec[MAXPATH]; - snprintf(fileSpec, MAXPATH, "%s/%s", filePath, ff_name); + pa_snprintf(fileSpec, MAXPATH, "%s/%s", filePath, ff_name); if(pa_stat(fileSpec, &_st) != 0) { memset(&_st,0,sizeof(_st));