libcryfs/test/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp

31 lines
723 B
C++
Raw Normal View History

2014-11-25 16:47:36 +01:00
#include "FuseCreateAndOpenTest.h"
using ::testing::_;
int FuseCreateAndOpenTest::CreateAndOpenFile(const char *filename, int flags) {
int fd = CreateAndOpenFileAllowError(filename, flags);
EXPECT_GE(fd, 0);
return fd;
}
int FuseCreateAndOpenTest::CreateAndOpenFileReturnError(const char *filename, int flags) {
int fd = CreateAndOpenFileAllowError(filename, flags);
if (fd >= 0) {
return 0;
} else {
return -fd;
}
}
2014-11-25 16:47:36 +01:00
int FuseCreateAndOpenTest::CreateAndOpenFileAllowError(const char *filename, int flags) {
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
int fd = ::open(realpath.c_str(), flags | O_CREAT);
if (fd >= 0) {
return fd;
} else {
return -errno;
}
2014-11-25 16:47:36 +01:00
}