forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisexecutable.cpp
More file actions
39 lines (34 loc) · 877 Bytes
/
Copy pathisexecutable.cpp
File metadata and controls
39 lines (34 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! @file isexecutable.cpp
//! @author George Fleming <v-geflem@microsoft.com>
//! @brief returns whether a file is executable
#include <errno.h>
#include <unistd.h>
#include <string>
#include "isexecutable.h"
//! @brief IsExecutable determines if path is executable
//!
//! IsExecutable
//!
//! @param[in] path
//! @parblock
//! A pointer to the buffer that contains the file name
//!
//! 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;
}
return access(path, X_OK) != -1;
}