--- parser3/src/main/pa_dir.C 2026/09/18 20:11:22 1.36 +++ parser3/src/main/pa_dir.C 2026/11/27 21:35:11 1.43 @@ -6,11 +6,13 @@ */ #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.36 2026/09/18 20:11:22 moko Exp $" IDENT_PA_DIR_H; +volatile const char * IDENT_PA_DIR_C="$Id: pa_dir.C,v 1.43 2026/11/27 21:35:11 moko Exp $" IDENT_PA_DIR_H; #ifdef _MSC_VER @@ -31,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) { @@ -55,6 +61,11 @@ bool ffblk::is_dir(bool) { return (stat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; } +bool ffblk::is_symlink() { + return (stat.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + && (stat.dwReserved0 == IO_REPARSE_TAG_SYMLINK || stat.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT); // junctions as well, but not the other reparse points [OneDrive, dedup] +} + double ffblk::size() { ULARGE_INTEGER ull; ull.LowPart = stat.nFileSizeLow; @@ -106,7 +117,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)); @@ -115,13 +126,25 @@ void ffblk::stat_file() { bool ffblk::is_dir(bool stat) { #ifdef HAVE_STRUCT_DIRENT_D_TYPE - if(!stat && _d_type != DT_UNKNOWN) + if(!stat && _d_type != DT_UNKNOWN && _d_type != DT_LNK) return _d_type == DT_DIR; #endif stat_file(); return S_ISDIR(_st.st_mode) != 0; } +bool ffblk::is_symlink() { +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + if(_d_type != DT_UNKNOWN) + return _d_type == DT_LNK; +#endif + char fileSpec[MAXPATH]; + pa_snprintf(fileSpec, MAXPATH, "%s/%s", filePath, ff_name); + + struct stat st; + return lstat(fileSpec, &st) == 0 && S_ISLNK(st.st_mode) != 0; +} + double ffblk::size() { return (double)_st.st_size; } @@ -139,16 +162,3 @@ time_t ffblk::a_timestamp() { } #endif - -#ifdef WIN32 -bool is_os_absolute_path(const String& path) { - return is_os_absolute_path(path.cstr()); -} - -bool is_os_absolute_path(const char* path) { - return path[0] && path[0]!=':' && path[1]==':' // DRIVE: (including drive-relative paths, for compatibility) - || path[0]=='\\' && path[1]=='\\' // UNC - || path[0]=='/' && path[1]=='/'; -} -#endif -