1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/file_descriptor_posix.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_FILE_DESCRIPTOR_POSIX_H_ 1.9 +#define BASE_FILE_DESCRIPTOR_POSIX_H_ 1.10 + 1.11 +namespace base { 1.12 + 1.13 +// ----------------------------------------------------------------------------- 1.14 +// We introduct a special structure for file descriptors in order that we are 1.15 +// able to use template specialisation to special-case their handling. 1.16 +// 1.17 +// WARNING: (Chromium only) There are subtleties to consider if serialising 1.18 +// these objects over IPC. See comments in ipc/ipc_message_utils.h 1.19 +// above the template specialisation for this structure. 1.20 +// ----------------------------------------------------------------------------- 1.21 +struct FileDescriptor { 1.22 + FileDescriptor() 1.23 + : fd(-1), 1.24 + auto_close(false) { } 1.25 + 1.26 + FileDescriptor(int ifd, bool iauto_close) 1.27 + : fd(ifd), 1.28 + auto_close(iauto_close) { } 1.29 + 1.30 + bool operator==(const FileDescriptor& other) const { 1.31 + return (fd == other.fd && auto_close == other.auto_close); 1.32 + } 1.33 + 1.34 + // A comparison operator so that we can use these as keys in a std::map. 1.35 + bool operator<(const FileDescriptor& other) const { 1.36 + return other.fd < fd; 1.37 + } 1.38 + 1.39 + int fd; 1.40 + // If true, this file descriptor should be closed after it has been used. For 1.41 + // example an IPC system might interpret this flag as indicating that the 1.42 + // file descriptor it has been given should be closed after use. 1.43 + bool auto_close; 1.44 +}; 1.45 + 1.46 +} // namespace base 1.47 + 1.48 +#endif // BASE_FILE_DESCRIPTOR_POSIX_H_