Clean up IsExecutable

This commit is contained in:
Andrew Schwartzmeyer
2016-10-14 15:42:59 -07:00
parent 8b3e8be1bc
commit 4038cd61f2
2 changed files with 3 additions and 19 deletions
+2 -12
View File
@@ -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;
}
+1 -7
View File
@@ -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)