file_descriptor_posix.cc 935 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2021 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. #include "base/file_descriptor_posix.h"
  5. #include "base/files/file.h"
  6. namespace base {
  7. FileDescriptor::FileDescriptor() = default;
  8. FileDescriptor::FileDescriptor(int ifd, bool iauto_close)
  9. : fd(ifd), auto_close(iauto_close) {}
  10. FileDescriptor::FileDescriptor(File file)
  11. : fd(file.TakePlatformFile()), auto_close(true) {}
  12. FileDescriptor::FileDescriptor(ScopedFD fd)
  13. : fd(fd.release()), auto_close(true) {}
  14. bool FileDescriptor::operator==(const FileDescriptor& other) const {
  15. return fd == other.fd && auto_close == other.auto_close;
  16. }
  17. bool FileDescriptor::operator!=(const FileDescriptor& other) const {
  18. return !operator==(other);
  19. }
  20. bool FileDescriptor::operator<(const FileDescriptor& other) const {
  21. return other.fd < fd;
  22. }
  23. } // namespace base