xref: /aosp_15_r20/external/cronet/base/file_descriptor_posix.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
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/file_descriptor_posix.h"
6 
7 #include "base/files/file.h"
8 
9 namespace base {
10 
11 FileDescriptor::FileDescriptor() = default;
12 
FileDescriptor(int ifd,bool iauto_close)13 FileDescriptor::FileDescriptor(int ifd, bool iauto_close)
14     : fd(ifd), auto_close(iauto_close) {}
15 
FileDescriptor(File file)16 FileDescriptor::FileDescriptor(File file)
17     : fd(file.TakePlatformFile()), auto_close(true) {}
18 
FileDescriptor(ScopedFD fd)19 FileDescriptor::FileDescriptor(ScopedFD fd)
20     : fd(fd.release()), auto_close(true) {}
21 
operator ==(const FileDescriptor & other) const22 bool FileDescriptor::operator==(const FileDescriptor& other) const {
23   return fd == other.fd && auto_close == other.auto_close;
24 }
25 
operator !=(const FileDescriptor & other) const26 bool FileDescriptor::operator!=(const FileDescriptor& other) const {
27   return !operator==(other);
28 }
29 
operator <(const FileDescriptor & other) const30 bool FileDescriptor::operator<(const FileDescriptor& other) const {
31   return other.fd < fd;
32 }
33 
34 }  // namespace base