[CMD] Code formatting for IsValidPathName, IsExistingFile, IsExistingDirectory, and use INVALID_FILE_ATTRIBUTES instead of an hardcoded value.

This commit is contained in:
Hermès Bélusca-Maïto 2020-09-04 00:17:15 +02:00
parent a5634138c3
commit 050df0f56d
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 20 additions and 21 deletions

View file

@ -297,9 +297,10 @@ LPTSTR *splitspace (LPTSTR, LPINT);
VOID freep (LPTSTR *);
LPTSTR _stpcpy (LPTSTR, LPCTSTR);
VOID StripQuotes(LPTSTR);
BOOL IsValidPathName (LPCTSTR);
BOOL IsExistingFile (LPCTSTR);
BOOL IsExistingDirectory (LPCTSTR);
BOOL IsValidPathName(IN LPCTSTR pszPath);
BOOL IsExistingFile(IN LPCTSTR pszPath);
BOOL IsExistingDirectory(IN LPCTSTR pszPath);
VOID GetPathCase(TCHAR *, TCHAR *);
#define PROMPT_NO 0

View file

@ -532,7 +532,7 @@ FileNameContainsSpecialCharacters(LPTSTR pszFileName)
(chr == _T('^')) ||
(chr == _T('~')) ||
(chr == _T('+')) ||
(chr == 0xB4)) // '´'
(chr == 0xB4)) // '´'
{
return TRUE;
}
@ -669,7 +669,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
/* Don't show files when they are doing 'cd' or 'rd' */
if (!ShowAll &&
file.dwFileAttributes != 0xFFFFFFFF &&
file.dwFileAttributes != INVALID_FILE_ATTRIBUTES &&
!(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
continue;

View file

@ -138,7 +138,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
attrs = GetFileAttributes(Right);
}
if (attrs == 0xFFFFFFFF)
if (attrs == INVALID_FILE_ATTRIBUTES)
result = FALSE;
else if (IsDir)
result = ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);

View file

@ -477,36 +477,34 @@ StripQuotes(TCHAR *in)
/*
* Checks if a path is valid (accessible)
* Checks if a path is valid (is accessible)
*/
BOOL IsValidPathName (LPCTSTR pszPath)
BOOL IsValidPathName(IN LPCTSTR pszPath)
{
TCHAR szOldPath[MAX_PATH];
BOOL bResult;
TCHAR szOldPath[MAX_PATH];
GetCurrentDirectory (MAX_PATH, szOldPath);
bResult = SetCurrentDirectory (pszPath);
GetCurrentDirectory(ARRAYSIZE(szOldPath), szOldPath);
bResult = SetCurrentDirectory(pszPath);
SetCurrentDirectory (szOldPath);
SetCurrentDirectory(szOldPath);
return bResult;
}
/*
* Checks if a file exists (accessible)
* Checks if a file exists (is accessible)
*/
BOOL IsExistingFile (LPCTSTR pszPath)
BOOL IsExistingFile(IN LPCTSTR pszPath)
{
DWORD attr = GetFileAttributes (pszPath);
return (attr != 0xFFFFFFFF && (! (attr & FILE_ATTRIBUTE_DIRECTORY)) );
DWORD attr = GetFileAttributes(pszPath);
return ((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
}
BOOL IsExistingDirectory (LPCTSTR pszPath)
BOOL IsExistingDirectory(IN LPCTSTR pszPath)
{
DWORD attr = GetFileAttributes (pszPath);
return (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_DIRECTORY) );
DWORD attr = GetFileAttributes(pszPath);
return ((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY));
}