forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissymlink.cpp
More file actions
40 lines (33 loc) · 802 Bytes
/
issymlink.cpp
File metadata and controls
40 lines (33 loc) · 802 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
40
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//! @brief returns whether a path is a symbolic link
#include "issymlink.h"
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string>
//! @brief IsSymlink determines if path is a symbolic link
//!
//! IsSymlink
//!
//! @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
//!
//! @retval true if path is a symbolic link, false otherwise
//!
bool IsSymLink(const char* path)
{
assert(path);
struct stat buf;
int32_t ret = lstat(path, &buf);
if (ret != 0)
{
return false;
}
return S_ISLNK(buf.st_mode);
}