Test Plan: fbconfig -r folly && fbmake opt -j32
@override-unit-failures
Reviewed By: soren@fb.com
FB internal diff:
D985595
checkFopenError(tmpFile, "tmpfile() failed");
SCOPE_EXIT { fclose(tmpFile); };
- int fd = dup(fileno(tmpFile));
+ int fd = ::dup(fileno(tmpFile));
checkUnixError(fd, "dup() failed");
return File(fd, true);
a.swap(b);
}
+File File::dup() const {
+ if (fd_ >= 0) {
+ int fd = ::dup(fd_);
+ checkUnixError(fd, "dup() failed");
+
+ return File(fd, true);
+ }
+
+ return File();
+}
+
void File::close() {
if (!closeNoThrow()) {
throwSystemError("close() failed");
return fd_ >= 0;
}
+ /**
+ * Duplicate file descriptor and return File that owns it.
+ */
+ File dup() const;
+
/**
* If we own the file descriptor, close the file and throw on error.
* Otherwise, do nothing.