--- parser3/src/main/pa_dir.C 2020/12/15 17:10:36 1.30 +++ parser3/src/main/pa_dir.C 2026/10/11 17:06:44 1.41 @@ -1,16 +1,18 @@ /** @file Parser: directory scanning for different OS-es. - Copyright (c) 2000-2020 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2000-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #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.30 2020/12/15 17:10:36 moko Exp $" IDENT_PA_DIR_H; +volatile const char * IDENT_PA_DIR_C="$Id: pa_dir.C,v 1.41 2026/10/11 17:06:44 moko Exp $" IDENT_PA_DIR_H; #ifdef _MSC_VER @@ -34,9 +36,13 @@ bool findfirst(const char* _pathname, st 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) { @@ -90,9 +96,8 @@ bool findnext(struct ffblk *_ffblk) { if(!entry) return true; - strncpy(_ffblk->ff_name, entry->d_name, sizeof(_ffblk->ff_name)-1); - _ffblk->ff_name[sizeof(_ffblk->ff_name)-1]=0; - + pa_strncpy(_ffblk->ff_name, entry->d_name, sizeof(_ffblk->ff_name)); + #ifdef HAVE_STRUCT_DIRENT_D_TYPE // http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html _ffblk->_d_type=entry->d_type;