Move IsDir() to utils.
This patch moves the generic IsDir() function to the utils.cc file
where other similar functions reside. It also adds unit tests for it.
BUG=None
TEST=Added unittests.
Change-Id: Iba05059f72a1156bb5f19ae0624ae7025af4c522
Reviewed-on: https://chromium-review.googlesource.com/200691
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/utils.cc b/utils.cc
index 6d2abac..70bcd34 100644
--- a/utils.cc
+++ b/utils.cc
@@ -520,6 +520,12 @@
return lstat(path, &stbuf) == 0 && S_ISLNK(stbuf.st_mode) != 0;
}
+bool IsDir(const char* path) {
+ struct stat stbuf;
+ TEST_AND_RETURN_FALSE_ERRNO(lstat(path, &stbuf) == 0);
+ return S_ISDIR(stbuf.st_mode);
+}
+
std::string TempFilename(string path) {
static const string suffix("XXXXXX");
CHECK(StringHasSuffix(path, suffix));