Skip to content

Commit

Permalink
Remove GetLStat
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Oct 14, 2016
1 parent b4b2278 commit 1d240ef
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 159 deletions.
1 change: 0 additions & 1 deletion src/libpsl-native/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add_library(psl-native SHARED
getstat.cpp
getlstat.cpp
getpwuid.cpp
getuserfrompid.cpp
getfileowner.cpp
Expand Down
96 changes: 0 additions & 96 deletions src/libpsl-native/src/getlstat.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/libpsl-native/src/getlstat.h

This file was deleted.

16 changes: 3 additions & 13 deletions src/libpsl-native/src/isfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! @author Andrew Schwartzmeyer <andschwa@microsoft.com>
//! @brief returns if the path exists

#include "getlstat.h"
#include "isfile.h"

#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
Expand All @@ -24,21 +23,12 @@
//! 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 path exists, false otherwise
//!
bool IsFile(const char* path)
{
errno = 0;

if (!path)
{
errno = ERROR_INVALID_PARAMETER;
return false;
}
assert(path);

struct stat buf;
return GetLStat(path, &buf) == 0;
return lstat(path, &buf) == 0;
}
28 changes: 3 additions & 25 deletions src/libpsl-native/src/issymlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! @author George FLeming <v-geflem@microsoft.com>
//! @brief returns whether a path is a symbolic link

#include "getlstat.h"
#include "issymlink.h"

#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand All @@ -22,36 +21,15 @@
//! char* is marshaled as an LPStr, which on Linux is UTF-8.
//! @endparblock
//!
//! @exception errno Passes these errors via errno to GetLastError:
//! - ERROR_INVALID_PARAMETER: parameter is not valid
//! - ERROR_FILE_NOT_FOUND: file does not exist
//! - ERROR_ACCESS_DENIED: access is denied
//! - ERROR_FILE_NOT_FOUND: the system cannot find the file specified
//! - ERROR_INVALID_ADDRESS: attempt to access invalid address
//! - ERROR_STOPPED_ON_SYMLINK: the operation stopped after reaching a symbolic link
//! - ERROR_GEN_FAILURE: device attached to the system is not functioning
//! - ERROR_NO_SUCH_USER: there was no corresponding entry in the utmp-file
//! - ERROR_INVALID_NAME: filename, directory name, or volume label syntax is incorrect
//! - ERROR_BUFFER_OVERFLOW: file name is too long
//! - ERROR_INVALID_FUNCTION: incorrect function
//! - ERROR_BAD_PATH_NAME: pathname is too long, or contains invalid characters
//!
//! @retval true if path is a symbolic link, false otherwise
//!

bool IsSymLink(const char* path)
{
errno = 0;

// Check parameters
if (!path)
{
errno = ERROR_INVALID_PARAMETER;
return false;
}
assert(path);

struct stat buf;
int32_t ret = GetLStat(path, &buf);
int32_t ret = lstat(path, &buf);
if (ret != 0)
{
return false;
Expand Down
8 changes: 1 addition & 7 deletions src/libpsl-native/test/test-isfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,5 @@ TEST(IsFileTest, BinLsIsFile)
TEST(IsFileTest, CannotGetOwnerOfFakeFile)
{
EXPECT_FALSE(IsFile("SomeMadeUpFileNameThatDoesNotExist"));
EXPECT_EQ(errno, ERROR_FILE_NOT_FOUND);
}

TEST(IsFileTest, ReturnsFalseForNullInput)
{
EXPECT_FALSE(IsFile(NULL));
EXPECT_EQ(errno, ERROR_INVALID_PARAMETER);
EXPECT_EQ(errno, ENOENT);
}
6 changes: 0 additions & 6 deletions src/libpsl-native/test/test-issymlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ class isSymLinkTest : public ::testing::Test
}
};

TEST_F(isSymLinkTest, FilePathNameIsNull)
{
EXPECT_FALSE(IsSymLink(NULL));
EXPECT_EQ(ERROR_INVALID_PARAMETER, errno);
}

TEST_F(isSymLinkTest, FilePathNameDoesNotExist)
{
std::string invalidFile = "/tmp/symlinktest_invalidFile";
Expand Down

0 comments on commit 1d240ef

Please sign in to comment.