From 21947380d96bd3d69cda964ce1b816b50914bd14 Mon Sep 17 00:00:00 2001
From: Avi Kivity <avi.kivity@gmail.com>
Date: Tue, 8 Jan 2013 13:04:49 +0200
Subject: [PATCH] fd: add get_fd() helper

---
 libc/fd.cc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libc/fd.cc b/libc/fd.cc
index 606c74234..03b0425a5 100644
--- a/libc/fd.cc
+++ b/libc/fd.cc
@@ -71,6 +71,19 @@ int open(const char* fname, int mode, ...)
     });
 }
 
+std::shared_ptr<file_desc> get_fd(int fd)
+{
+    if (fd < 0) {
+        return std::shared_ptr<file_desc>();
+    }
+    return with_lock(file_table_mutex, [=] {
+        if (size_t(fd) >= file_table.size()) {
+            return std::shared_ptr<file_desc>();
+        }
+        return file_table[fd];
+    });
+}
+
 namespace {
 
 int do_stat1(fileref f, struct stat* buf)
-- 
GitLab