platform_file.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 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. #ifndef BASE_FILES_PLATFORM_FILE_H_
  5. #define BASE_FILES_PLATFORM_FILE_H_
  6. #include "base/files/scoped_file.h"
  7. #include "build/build_config.h"
  8. #if defined(OS_WIN)
  9. #include "base/win/scoped_handle.h"
  10. #include "base/win/windows_types.h"
  11. #endif
  12. // This file defines platform-independent types for dealing with
  13. // platform-dependent files. If possible, use the higher-level base::File class
  14. // rather than these primitives.
  15. namespace base {
  16. #if defined(OS_WIN)
  17. using PlatformFile = HANDLE;
  18. using ScopedPlatformFile = ::base::win::ScopedHandle;
  19. // It would be nice to make this constexpr but INVALID_HANDLE_VALUE is a
  20. // ((void*)(-1)) which Clang rejects since reinterpret_cast is technically
  21. // disallowed in constexpr. Visual Studio accepts this, however.
  22. const PlatformFile kInvalidPlatformFile = INVALID_HANDLE_VALUE;
  23. #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
  24. using PlatformFile = int;
  25. using ScopedPlatformFile = ::base::ScopedFD;
  26. constexpr PlatformFile kInvalidPlatformFile = -1;
  27. #endif
  28. } // namespace
  29. #endif // BASE_FILES_PLATFORM_FILE_H_