From de4dfee6559590d7a0ef954fc03fb0bd01902801 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 2 Jan 2022 19:48:53 +0000 Subject: Refactor code for further code improvements. * file_io/win32/filestat.c (apr_file_info_get): Inline fillin_fileinfo() to apr_file_info_get(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1896625 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/filestat.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'file_io') diff --git a/file_io/win32/filestat.c b/file_io/win32/filestat.c index 0138341dc..6a9ff89f2 100644 --- a/file_io/win32/filestat.c +++ b/file_io/win32/filestat.c @@ -489,7 +489,57 @@ APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, apr_int32_t want return apr_get_os_error(); } - fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) &FileInfo, 1, 0, thefile->fname, wanted); + memset(finfo, '\0', sizeof(*finfo)); + + FileTimeToAprTime(&finfo->atime, &FileInfo.ftLastAccessTime); + FileTimeToAprTime(&finfo->ctime, &FileInfo.ftCreationTime); + FileTimeToAprTime(&finfo->mtime, &FileInfo.ftLastWriteTime); + +#if APR_HAS_LARGE_FILES + finfo->size = (apr_off_t)FileInfo.nFileSizeLow + | ((apr_off_t)FileInfo.nFileSizeHigh << 32); +#else + finfo->size = (apr_off_t)FileInfo.nFileSizeLow; + if (finfo->size < 0 || FileInfo.nFileSizeHigh) + finfo->size = 0x7fffffff; +#endif + + if (wanted & APR_FINFO_LINK && + reparse_point_is_link(&FileInfo, 0, thefile->fname)) { + finfo->filetype = APR_LNK; + } + else if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + finfo->filetype = APR_DIR; + } + else if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) { + /* Warning: This test only succeeds on Win9x, on NT these files + * (con, aux, nul, lpt#, com# etc) escape early detection! + */ + finfo->filetype = APR_CHR; + } + else { + /* Warning: Short of opening the handle to the file, the 'FileType' + * appears to be unknowable (in any trustworthy or consistent sense) + * on WinNT/2K as far as PIPE, CHR, etc are concerned. + */ + finfo->filetype = APR_REG; + } + + /* The following flags are [for this moment] private to Win32. + * That's the only excuse for not toggling valid bits to reflect them. + */ + if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) + finfo->protection = APR_FREADONLY; + + finfo->valid = APR_FINFO_ATIME | APR_FINFO_CTIME | APR_FINFO_MTIME + | APR_FINFO_SIZE | APR_FINFO_TYPE; /* == APR_FINFO_MIN */ + + /* Only byhandle optionally tests link targets, so tell that caller + * what it wants to hear, otherwise the byattributes is never + * reporting anything but the link. + */ + if (wanted & APR_FINFO_LINK) + finfo->valid |= APR_FINFO_LINK; if (finfo->filetype == APR_REG) { -- cgit v1.2.1