1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34

base / file_descriptor_posix.cc [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_descriptor_posix.h"

#include "base/files/file.h"

namespace base {

FileDescriptor::FileDescriptor() = default;

FileDescriptor::FileDescriptor(int ifd, bool iauto_close)
    : fd(ifd), auto_close(iauto_close) {}

FileDescriptor::FileDescriptor(File file)
    : fd(file.TakePlatformFile()), auto_close(true) {}

FileDescriptor::FileDescriptor(ScopedFD fd)
    : fd(fd.release()), auto_close(true) {}

bool FileDescriptor::operator==(const FileDescriptor& other) const {
  return fd == other.fd && auto_close == other.auto_close;
}

bool FileDescriptor::operator!=(const FileDescriptor& other) const {
  return !operator==(other);
}

bool FileDescriptor::operator<(const FileDescriptor& other) const {
  return other.fd < fd;
}

}  // namespace base