Commit b4ca09ac by Jamie Madill Committed by Commit Bot

Add IsDirectory helper function to system_utils.

This was previously a method in dEQP only. Cleanup change only. Bug: angleproject:3353 Change-Id: I9ac58ab52516f75efbb08bddb39466a40c07cbb8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1613892 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 38ff3c70
......@@ -10,7 +10,6 @@
namespace angle
{
bool PrependPathToEnvironmentVar(const char *variableName, const char *path)
{
std::string oldValue = GetEnvironmentVar(variableName);
......@@ -29,5 +28,4 @@ bool PrependPathToEnvironmentVar(const char *variableName, const char *path)
}
return SetEnvironmentVar(variableName, newValue);
}
} // namespace angle
......@@ -24,6 +24,7 @@ bool UnsetEnvironmentVar(const char *variableName);
std::string GetEnvironmentVar(const char *variableName);
const char *GetPathSeparator();
bool PrependPathToEnvironmentVar(const char *variableName, const char *path);
bool IsDirectory(const char *filename);
// Run an application and get the output. Gets a nullptr-terminated set of args to execute the
// application with, and returns the stdout and stderr outputs as well as the exit code.
......
......@@ -11,6 +11,7 @@
#include <array>
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
......@@ -255,4 +256,11 @@ Library *OpenSharedLibrary(const char *libraryName)
{
return new PosixLibrary(libraryName);
}
bool IsDirectory(const char *filename)
{
struct stat st;
int result = stat(filename, &st);
return result == 0 && ((st.st_mode & S_IFDIR) == S_IFDIR);
}
} // namespace angle
......@@ -283,4 +283,18 @@ Library *OpenSharedLibrary(const char *libraryName)
{
return new Win32Library(libraryName);
}
bool IsDirectory(const char *filename)
{
WIN32_FILE_ATTRIBUTE_DATA fileInformation;
BOOL result = GetFileAttributesExA(filename, GetFileExInfoStandard, &fileInformation);
if (result)
{
DWORD attribs = fileInformation.dwFileAttributes;
return (attribs != INVALID_FILE_ATTRIBUTES) && ((attribs & FILE_ATTRIBUTE_DIRECTORY) > 0);
}
return false;
}
} // namespace angle
......@@ -22,16 +22,6 @@
#include "tcuTestLog.hpp"
#include "util/system_utils.h"
#if (DE_OS == DE_OS_WIN32)
# include <Windows.h>
#elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_OSX)
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/unistd.h>
#elif (DE_OS == DE_OS_ANDROID)
# include <sys/stat.h>
#endif
tcu::Platform *CreateANGLEPlatform(angle::LogErrorFunc logErrorFunc);
namespace
......@@ -55,37 +45,11 @@ const char *g_dEQPDataSearchDirs[] = {
"third_party/deqp/src/data",
};
// TODO(jmadill): upstream to dEQP?
#if (DE_OS == DE_OS_WIN32)
deBool deIsDir(const char *filename)
{
WIN32_FILE_ATTRIBUTE_DATA fileInformation;
BOOL result = GetFileAttributesExA(filename, GetFileExInfoStandard, &fileInformation);
if (result)
{
DWORD attribs = fileInformation.dwFileAttributes;
return (attribs != INVALID_FILE_ATTRIBUTES) && ((attribs & FILE_ATTRIBUTE_DIRECTORY) > 0);
}
return false;
}
#elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_ANDROID)
deBool deIsDir(const char *filename)
{
struct stat st;
int result = stat(filename, &st);
return result == 0 && ((st.st_mode & S_IFDIR) == S_IFDIR);
}
#else
# error TODO(jmadill): support other platforms
#endif
bool FindDataDir(std::string *dataDirOut)
{
for (auto searchDir : g_dEQPDataSearchDirs)
{
if (deIsDir((std::string(searchDir) + "/gles2").c_str()))
if (angle::IsDirectory((std::string(searchDir) + "/gles2").c_str()))
{
*dataDirOut = searchDir;
return true;
......@@ -97,7 +61,7 @@ bool FindDataDir(std::string *dataDirOut)
dirStream << "/gles2";
std::string searchPath = dirStream.str();
if (deIsDir(searchPath.c_str()))
if (angle::IsDirectory(searchPath.c_str()))
{
*dataDirOut = dataDir;
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment