flutter_flutter/fml/unique_fd.h
Chris Bracken 08dabe9601
Clean up C++ includes (#21127)
Cleans up header order/grouping for consistency: associated header, C/C++ system/standard library headers, library headers, platform-specific #includes.

Adds <cstring> where strlen, memcpy are being used: there are a bunch of places we use them transitively.

Applies linter-required cleanups. Disables linter on one file due to included RapidJson header. See https://github.com/flutter/flutter/issues/65676

This patch does not cover flutter/shell/platform/darwin. There's a separate, slightly more intensive cleanup for those in progress.
2020-09-11 21:18:35 -07:00

69 lines
1.4 KiB
C++

// Copyright 2013 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/build_config.h"
#include "flutter/fml/unique_object.h"
#if OS_WIN
#include <windows.h>
#else // OS_WIN
#include <dirent.h>
#include <unistd.h>
#endif // OS_WIN
namespace fml {
namespace internal {
#if OS_WIN
namespace os_win {
struct UniqueFDTraits {
static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
static bool IsValid(HANDLE value) { return value != InvalidValue(); }
static void Free(HANDLE fd);
};
} // namespace os_win
#else // OS_WIN
namespace os_unix {
struct UniqueFDTraits {
static int InvalidValue() { return -1; }
static bool IsValid(int value) { return value >= 0; }
static void Free(int fd);
};
struct UniqueDirTraits {
static DIR* InvalidValue() { return nullptr; }
static bool IsValid(DIR* value) { return value != nullptr; }
static void Free(DIR* dir);
};
} // namespace os_unix
#endif // OS_WIN
} // namespace internal
#if OS_WIN
using UniqueFD = UniqueObject<HANDLE, internal::os_win::UniqueFDTraits>;
#else // OS_WIN
using UniqueFD = UniqueObject<int, internal::os_unix::UniqueFDTraits>;
using UniqueDir = UniqueObject<DIR*, internal::os_unix::UniqueDirTraits>;
#endif // OS_WIN
} // namespace fml
#endif // FLUTTER_FML_UNIQUE_FD_H_