unique_fd.h 1.1 KB
Newer Older
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
// Copyright 2018 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_FML_UNIQUE_FD_H_
#define FLUTTER_FML_UNIQUE_FD_H_

#include "flutter/fml/unique_object.h"
#include "lib/fxl/build_config.h"

#if OS_WIN

#include <windows.h>

#endif  // OS_WIN

namespace fml {
namespace internal {

#if OS_WIN

namespace win {

struct UniqueFDTraits {
  static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
  static bool IsValid(HANDLE value) { return value != InvalidValue(); }
  static void Free(HANDLE fd);
};

}  // namespace win

#else  // OS_WIN

namespace unix {

struct UniqueFDTraits {
  static int InvalidValue() { return -1; }
  static bool IsValid(int value) { return value >= 0; }
  static void Free(int fd);
};

}  // namespace unix

#endif  // OS_WIN

}  // namespace internal

#if OS_WIN

using UniqueFD = UniqueObject<HANDLE, internal::win::UniqueFDTraits>;

#else  // OS_WIN

using UniqueFD = UniqueObject<int, internal::unix::UniqueFDTraits>;

#endif  // OS_WIN

}  // namespace fml

#endif  // FLUTTER_FML_UNIQUE_FD_H_