mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Clean up IsDirectory
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "getfileowner.h"
|
||||
#include "isdirectory.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
@@ -25,20 +25,11 @@
|
||||
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
|
||||
//! @endparblock
|
||||
//!
|
||||
//! @exception errno Passes this error via errno to GetLastError:
|
||||
//! - ERROR_INVALID_PARAMETER: parameter is not valid
|
||||
//!
|
||||
//! @retval true if directory, false otherwise
|
||||
//!
|
||||
bool IsDirectory(const char* path)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (!path)
|
||||
{
|
||||
errno = ERROR_INVALID_PARAMETER;
|
||||
return false;
|
||||
}
|
||||
assert(path);
|
||||
|
||||
struct stat buf;
|
||||
int32_t ret = GetStat(path, &buf);
|
||||
|
||||
@@ -21,11 +21,5 @@ TEST(IsDirectoryTest, BinLsIsNotDirectory)
|
||||
TEST(IsDirectoryTest, ReturnsFalseForFakeDirectory)
|
||||
{
|
||||
EXPECT_FALSE(IsDirectory("SomeMadeUpFileNameThatDoesNotExist"));
|
||||
EXPECT_EQ(errno, ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
TEST(IsDirectoryTest, ReturnsFalseForNullInput)
|
||||
{
|
||||
EXPECT_FALSE(IsDirectory(NULL));
|
||||
EXPECT_EQ(errno, ERROR_INVALID_PARAMETER);
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user