projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix integer sign consistency.
[folly.git]
/
folly
/
File.cpp
diff --git
a/folly/File.cpp
b/folly/File.cpp
index 0dece45d6525ac58ec08544a8d07e57aafa784ec..2fa8e2b77e93b0747b01226ca04e69a45cdde151 100644
(file)
--- a/
folly/File.cpp
+++ b/
folly/File.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
5
Facebook, Inc.
+ * Copyright 201
3-present
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-16,13
+16,14
@@
#include <folly/File.h>
#include <folly/File.h>
-#include <fcntl.h>
-#include <unistd.h>
#include <folly/Exception.h>
#include <folly/FileUtil.h>
#include <folly/Format.h>
#include <folly/ScopeGuard.h>
#include <folly/Exception.h>
#include <folly/FileUtil.h>
#include <folly/Format.h>
#include <folly/ScopeGuard.h>
+#include <folly/portability/Fcntl.h>
+#include <folly/portability/SysFile.h>
+#include <folly/portability/Unistd.h>
#include <system_error>
#include <system_error>
@@
-30,14
+31,9
@@
namespace folly {
namespace folly {
-File::File()
- : fd_(-1)
- , ownsFd_(false)
-{}
+File::File() noexcept : fd_(-1), ownsFd_(false) {}
-File::File(int fd, bool ownsFd)
- : fd_(fd)
- , ownsFd_(ownsFd) {
+File::File(int fd, bool ownsFd) noexcept : fd_(fd), ownsFd_(ownsFd) {
CHECK_GE(fd, -1) << "fd must be -1 or non-negative";
CHECK(fd != -1 || !ownsFd) << "cannot own -1";
}
CHECK_GE(fd, -1) << "fd must be -1 or non-negative";
CHECK(fd != -1 || !ownsFd) << "cannot own -1";
}
@@
-52,6
+48,12
@@
File::File(const char* name, int flags, mode_t mode)
ownsFd_ = true;
}
ownsFd_ = true;
}
+File::File(const std::string& name, int flags, mode_t mode)
+ : File(name.c_str(), flags, mode) {}
+
+File::File(StringPiece name, int flags, mode_t mode)
+ : File(name.str(), flags, mode) {}
+
File::File(File&& other) noexcept
: fd_(other.fd_)
, ownsFd_(other.ownsFd_) {
File::File(File&& other) noexcept
: fd_(other.fd_)
, ownsFd_(other.ownsFd_) {
@@
-65,7
+67,11
@@
File& File::operator=(File&& other) {
}
File::~File() {
}
File::~File() {
- closeNoThrow(); // ignore error
+ auto fd = fd_;
+ if (!closeNoThrow()) { // ignore most errors
+ DCHECK_NE(errno, EBADF) << "closing fd " << fd << ", it may already "
+ << "have been closed. Another time, this might close the wrong FD.";
+ }
}
/* static */ File File::temporary() {
}
/* static */ File File::temporary() {
@@
-132,7
+138,9
@@
void File::doLock(int op) {
bool File::doTryLock(int op) {
int r = flockNoInt(fd_, op | LOCK_NB);
// flock returns EWOULDBLOCK if already locked
bool File::doTryLock(int op) {
int r = flockNoInt(fd_, op | LOCK_NB);
// flock returns EWOULDBLOCK if already locked
- if (r == -1 && errno == EWOULDBLOCK) return false;
+ if (r == -1 && errno == EWOULDBLOCK) {
+ return false;
+ }
checkUnixError(r, "flock() failed (try_lock)");
return true;
}
checkUnixError(r, "flock() failed (try_lock)");
return true;
}
@@
-142,4
+150,4
@@
void File::unlock() {
}
void File::unlock_shared() { unlock(); }
}
void File::unlock_shared() { unlock(); }
-}
// namespace folly
+} // namespace folly