OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/shared_memory_handle.h" |
| 6 |
| 7 #include <sys/stat.h> |
| 8 |
| 9 #include "base/strings/stringprintf.h" |
| 10 |
| 11 namespace base { |
| 12 |
| 13 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
| 14 |
| 15 bool GetIDFromSharedMemoryHandle(const SharedMemoryHandle& handle, |
| 16 SharedMemoryHandleID* id) { |
| 17 // Get file name? |
| 18 struct stat file_stat; |
| 19 if (fstat(static_cast<int>(handle.fd), &file_stat) != 0) |
| 20 return false; |
| 21 id->device_id = file_stat.st_dev; |
| 22 id->file_id = file_stat.st_ino; |
| 23 return true; |
| 24 } |
| 25 |
| 26 std::string GetSharedMemoryHandleIDString(const SharedMemoryHandleID& id) { |
| 27 return base::StringPrintf("%lld.%lld", static_cast<long long>(id.device_id), |
| 28 static_cast<long long>(id.file_id)); |
| 29 } |
| 30 |
| 31 #endif |
| 32 |
| 33 } // namespace base |
OLD | NEW |