return ((stats.st_mode & S_IFMT) == S_IFDIR);
}
+bool
+isFile(const string& name) {
+ struct stat stats;
+ if (::stat(name.c_str(), &stats) < 0) {
+ return (false);
+ }
+ return ((stats.st_mode & S_IFMT) == S_IFREG);
+}
+
+
} // namespace file
} // namespace log
} // namespace isc
/// @throw BadValue when the file can't be opened or is not a regular one.
std::string getContent(const std::string& file_name);
-/// @brief Is a directory predicate.
+/// @brief Check if there is a directory at the given path.
///
-/// @param name The file or directory name.
+/// @param name the path being checked.
/// @return True if the name points to a directory, false otherwise including
/// if the pointed location does not exist.
bool isDir(const std::string& name);
+/// @brief Check if there is a file at the given path.
+///
+/// @param name the path being checked.
+/// @return True if the name points to a file, false otherwise including
+/// if the pointed location does not exist.
+bool isFile(const std::string& name);
+
} // namespace file
} // namespace util
} // namespace isc
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_builddir)\"
-# XXX: we'll pollute the top builddir for creating a temporary test file
-# used to bind a UNIX domain socket so we can minimize the risk of exceeding
-# the limit of file name path size.
-AM_CPPFLAGS += -DTEST_DATA_TOPBUILDDIR=\"$(abs_top_builddir)\"
AM_CXXFLAGS = $(KEA_CXXFLAGS)
if USE_STATIC_LINK
EXPECT_FALSE(isDir("/etc/hosts"));
}
+/// @brief Check isFile.
+TEST_F(FileUtilTest, isFile) {
+ EXPECT_TRUE(isFile("file_utilities_unittest.cc"));
+ EXPECT_FALSE(isFile(TEST_DATA_BUILDDIR));
}
+
+} // namespace