Flutter Engine
unique_fd.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 
5 #ifndef FLUTTER_FML_UNIQUE_FD_H_
6 #define FLUTTER_FML_UNIQUE_FD_H_
7 
8 #include "flutter/fml/build_config.h"
9 #include "flutter/fml/unique_object.h"
10 
11 #if OS_WIN
12 #include <windows.h>
13 #else // OS_WIN
14 #include <dirent.h>
15 #include <unistd.h>
16 #endif // OS_WIN
17 
18 namespace fml {
19 namespace internal {
20 
21 #if OS_WIN
22 
23 namespace os_win {
24 
25 struct UniqueFDTraits {
26  static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
27  static bool IsValid(HANDLE value) { return value != InvalidValue(); }
28  static void Free(HANDLE fd);
29 };
30 
31 } // namespace os_win
32 
33 #else // OS_WIN
34 
35 namespace os_unix {
36 
38  static int InvalidValue() { return -1; }
39  static bool IsValid(int value) { return value >= 0; }
40  static void Free(int fd);
41 };
42 
44  static DIR* InvalidValue() { return nullptr; }
45  static bool IsValid(DIR* value) { return value != nullptr; }
46  static void Free(DIR* dir);
47 };
48 
49 } // namespace os_unix
50 
51 #endif // OS_WIN
52 
53 } // namespace internal
54 
55 #if OS_WIN
56 
58 
59 #else // OS_WIN
60 
63 
64 #endif // OS_WIN
65 
66 } // namespace fml
67 
68 #endif // FLUTTER_FML_UNIQUE_FD_H_
static bool IsValid(DIR *value)
Definition: unique_fd.h:45
Definition: ascii_trie.cc:9
static bool IsValid(int value)
Definition: unique_fd.h:39
uint8_t value