Add File::Duplicate to duplicate a file handle.
BUG=462584
R=rvargas@chromium.org
Review URL: https://codereview.chromium.org/1017243002
Cr-Commit-Position: refs/heads/master@{#321389}
CrOS-Libchrome-Original-Commit: bad5603dd8bbcf7583e8e483f8198e9b88f1c079
diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
index 663f099..517390f 100644
--- a/base/files/file_posix.cc
+++ b/base/files/file_posix.cc
@@ -463,6 +463,20 @@
return CallFctnlFlock(file_.get(), false);
}
+File File::Duplicate() {
+ if (!IsValid())
+ return File();
+
+ PlatformFile other_fd = dup(GetPlatformFile());
+ if (other_fd == -1)
+ return File(OSErrorToFileError(errno));
+
+ File other(other_fd);
+ if (async())
+ other.async_ = true;
+ return other.Pass();
+}
+
// Static.
File::Error File::OSErrorToFileError(int saved_errno) {
switch (saved_errno) {