chromium/third_party/libc++/src/src/filesystem/file_descriptor.h

//===----------------------------------------------------------------------===////
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===////

#ifndef FILESYSTEM_FILE_DESCRIPTOR_H
#define FILESYSTEM_FILE_DESCRIPTOR_H

#include <__config>
#include <cstdint>
#include <filesystem>
#include <string_view>
#include <system_error>
#include <utility>

#include "error.h"
#include "posix_compat.h"
#include "time_utils.h"

#if defined(_LIBCPP_WIN32API)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#  include <windows.h>
#else
#  include <dirent.h> // for DIR & friends
#  include <fcntl.h>  // values for fchmodat
#  include <sys/stat.h>
#  include <sys/statvfs.h>
#  include <unistd.h>
#endif // defined(_LIBCPP_WIN32API)

_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM

namespace detail {

#if !defined(_LIBCPP_WIN32API)

#  if defined(DT_BLK)
template <class DirEntT, class = decltype(DirEntT::d_type)>
file_type get_file_type(DirEntT* ent, int) {}
#  endif // defined(DT_BLK)

template <class DirEntT>
file_type get_file_type(DirEntT*, long) {}

inline pair<string_view, file_type> posix_readdir(DIR* dir_stream, error_code& ec) {}

#else // _LIBCPP_WIN32API

inline file_type get_file_type(const WIN32_FIND_DATAW& data) {
  if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
    return file_type::symlink;
  if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    return file_type::directory;
  return file_type::regular;
}
inline uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
  return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
}
inline file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
  ULARGE_INTEGER tmp;
  const FILETIME& time = data.ftLastWriteTime;
  tmp.u.LowPart        = time.dwLowDateTime;
  tmp.u.HighPart       = time.dwHighDateTime;
  return file_time_type(file_time_type::duration(tmp.QuadPart));
}

#endif // !_LIBCPP_WIN32API

//                       POSIX HELPERS

value_type;
string_type;

struct FileDescriptor {};

inline perms posix_get_perms(const StatT& st) noexcept {}

inline file_status create_file_status(error_code& m_ec, path const& p, const StatT& path_stat, error_code* ec) {}

inline file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) {}

inline file_status posix_stat(path const& p, error_code* ec) {}

inline file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) {}

inline file_status posix_lstat(path const& p, error_code* ec) {}

// http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
inline bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) {}

inline bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) {}

inline bool stat_equivalent(const StatT& st1, const StatT& st2) {}

inline file_status FileDescriptor::refresh_status(error_code& ec) {}

} // end namespace detail

_LIBCPP_END_NAMESPACE_FILESYSTEM

#endif // FILESYSTEM_FILE_DESCRIPTOR_H