portability improvement. replace POSIX-only functionality.

This commit is contained in:
Axel Kohlmeyer
2021-04-24 07:14:29 -04:00
parent e980d17882
commit 0aa64eaf14

View File

@ -10,14 +10,12 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#ifndef TEST_EXTENSIONS__H #ifndef LMP_TESTING_UTILS_H
#define TEST_EXTENSIONS__H #define LMP_TESTING_UTILS_H
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector> #include <vector>
static void delete_file(const std::string &filename) static void delete_file(const std::string &filename)
@ -65,8 +63,8 @@ static std::vector<std::string> read_lines(const std::string &filename)
static bool file_exists(const std::string &filename) static bool file_exists(const std::string &filename)
{ {
struct stat result; std::ifstream infile(filename);
return stat(filename.c_str(), &result) == 0; return infile.good();
} }
#define ASSERT_FILE_EXISTS(NAME) ASSERT_TRUE(file_exists(NAME)) #define ASSERT_FILE_EXISTS(NAME) ASSERT_TRUE(file_exists(NAME))