#include "folly/File.h"
-#include <sys/file.h>
#include <fcntl.h>
#include <unistd.h>
-#include "folly/Format.h"
#include "folly/Exception.h"
+#include "folly/FileUtil.h"
+#include "folly/Format.h"
#include "folly/ScopeGuard.h"
#include <system_error>
bool File::try_lock_shared() { return doTryLock(LOCK_SH); }
void File::doLock(int op) {
- checkUnixError(flock(fd_, op), "flock() failed (lock)");
+ checkUnixError(flockNoInt(fd_, op), "flock() failed (lock)");
}
bool File::doTryLock(int op) {
- int r = flock(fd_, op | LOCK_NB);
+ int r = flockNoInt(fd_, op | LOCK_NB);
// flock returns EWOULDBLOCK if already locked
if (r == -1 && errno == EWOULDBLOCK) return false;
checkUnixError(r, "flock() failed (try_lock)");
}
void File::unlock() {
- checkUnixError(flock(fd_, LOCK_UN), "flock() failed (unlock)");
+ checkUnixError(flockNoInt(fd_, LOCK_UN), "flock() failed (unlock)");
}
void File::unlock_shared() { unlock(); }
#ifdef __APPLE__
#include <fcntl.h>
#endif
+#include <sys/file.h>
#include "folly/detail/FileUtilDetail.h"
return wrapNoInt(truncate, path, len);
}
+int flockNoInt(int fd, int operation) {
+ return wrapNoInt(flock, fd, operation);
+}
+
ssize_t readNoInt(int fd, void* buf, size_t count) {
return wrapNoInt(read, fd, buf, count);
}
int fdatasyncNoInt(int fd);
int ftruncateNoInt(int fd, off_t len);
int truncateNoInt(const char* path, off_t len);
+int flockNoInt(int fd, int operation);
ssize_t readNoInt(int fd, void* buf, size_t n);
ssize_t preadNoInt(int fd, void* buf, size_t n, off_t offset);