mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Clean up IsExecutable
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "isexecutable.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
@@ -19,22 +19,12 @@
|
||||
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
|
||||
//! @endparblock
|
||||
//!
|
||||
//! @exception errno Passes these errors via errno to GetLastError:
|
||||
//! - ERROR_INVALID_ADDRESS: attempt to access invalid address
|
||||
//!
|
||||
//! @retval true if path is an executable, false otherwise
|
||||
//!
|
||||
|
||||
bool IsExecutable(const char* path)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
// Check parameters
|
||||
if (!path)
|
||||
{
|
||||
errno = ERROR_INVALID_PARAMETER;
|
||||
return false;
|
||||
}
|
||||
assert(path);
|
||||
|
||||
return access(path, X_OK) != -1;
|
||||
}
|
||||
|
||||
@@ -47,17 +47,11 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(IsExecutableTest, FilePathNameIsNull)
|
||||
{
|
||||
EXPECT_FALSE(IsExecutable(NULL));
|
||||
EXPECT_EQ(ERROR_INVALID_PARAMETER, errno);
|
||||
}
|
||||
|
||||
TEST_F(IsExecutableTest, FilePathNameDoesNotExist)
|
||||
{
|
||||
std::string invalidFile = "/tmp/isexecutabletest_invalidFile";
|
||||
EXPECT_FALSE(IsExecutable(invalidFile.c_str()));
|
||||
EXPECT_EQ(ERROR_FILE_NOT_FOUND, errno);
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
TEST_F(IsExecutableTest, NormalFileIsNotIsexecutable)
|
||||
|
||||
Reference in New Issue
Block a user