Skip to content

Commit

Permalink
useing char8_t on win9x
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroModel committed Nov 11, 2024
1 parent dc7c457 commit eb96c4c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
58 changes: 30 additions & 28 deletions include/fast_io_hosted/filesystem/win9x.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace fast_io
struct win9x_dirent
{
void *file_struct{};
::fast_io::string find_path{};
::fast_io::u8string find_path{};

::fast_io::win9x_dir_handle d_handle{};
file_type d_type{};
::std::uint_least64_t d_ino{};
::fast_io::string filename{};
::fast_io::u8string filename{};

~win9x_dirent()
{
Expand All @@ -28,8 +28,8 @@ inline bool set_win9x_dirent(win9x_dirent &entry, bool start)
::fast_io::win32::win32_find_dataa wfda{};
if (start)
{
entry.find_path = ::fast_io::concat_fast_io(entry.d_handle.path, "\\*");
entry.file_struct = ::fast_io::win32::FindFirstFileA(entry.find_path.c_str(), __builtin_addressof(wfda));
entry.find_path = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(entry.d_handle.path), u8"\\*");
entry.file_struct = ::fast_io::win32::FindFirstFileA(reinterpret_cast<char const *>(entry.find_path.c_str()), __builtin_addressof(wfda));
}
else
{
Expand All @@ -39,7 +39,7 @@ inline bool set_win9x_dirent(win9x_dirent &entry, bool start)
}
}

entry.filename = ::fast_io::string{::fast_io::mnp::os_c_str(wfda.cFileName)};
entry.filename = ::fast_io::u8string{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt_os_c_str(wfda.cFileName))};

if (wfda.dwFileAttributes & 0x400)
{
Expand Down Expand Up @@ -79,9 +79,9 @@ inline bool win9x_dirent_next(win9x_dirent &entry)

struct win9x_directory_entry
{
using native_char_type = char;
using native_char_type = char8_t;
using char_type = char8_t;
win9x_dirent* entry{};
win9x_dirent *entry{};
template <nt_family family, ::std::integral ch_type>
explicit constexpr operator basic_nt_family_io_observer<family, ch_type>() const noexcept
{
Expand All @@ -103,7 +103,7 @@ inline constexpr win9x_at_entry at(win9x_directory_entry ndet) noexcept
return win9x_at_entry{ndet.entry->d_handle};
}

inline constexpr ::fast_io::manipulators::basic_os_c_str_with_known_size<char>
inline constexpr ::fast_io::manipulators::basic_os_c_str_with_known_size<char8_t>
native_filename(win9x_directory_entry pioe) noexcept
{
auto &ent{*pioe.entry};
Expand All @@ -129,7 +129,7 @@ u8filename(win9x_directory_entry pioe) noexcept
return {reinterpret_cast<char8_may_alias_const_ptr>(ent.filename.c_str()), ent.filename.size()};
}

inline constexpr ::std::uint_least64_t inode_ul64(win9x_directory_entry ) noexcept
inline constexpr ::std::uint_least64_t inode_ul64(win9x_directory_entry) noexcept
{
return 0;
}
Expand All @@ -142,9 +142,9 @@ inline constexpr file_type type(win9x_directory_entry pioe) noexcept
inline bool is_dot(win9x_directory_entry ent) noexcept
{
::std::size_t const native_d_namlen{ent.entry->filename.size()};
char const *native_d_name_ptr{ent.entry->filename.c_str()};
return ((native_d_namlen == 1 && *native_d_name_ptr == '.') ||
(native_d_namlen == 2 && *native_d_name_ptr == '.' && native_d_name_ptr[1] == '.'));
char8_t const *native_d_name_ptr{ent.entry->filename.c_str()};
return ((native_d_namlen == 1 && *native_d_name_ptr == u8'.') ||
(native_d_namlen == 2 && *native_d_name_ptr == u8'.' && native_d_name_ptr[1] == u8'.'));
}

struct win9x_family_directory_iterator
Expand Down Expand Up @@ -239,12 +239,12 @@ struct basic_win9x_recursive_directory_iterator
using stack_type = StackType;
::fast_io::win9x_dir_handle root_handle{};
void *root_file_struct{};
win9x_dirent* entry{};
win9x_dirent *entry{};
stack_type stack;
bool finish{};
constexpr basic_win9x_recursive_directory_iterator() = default;

explicit constexpr basic_win9x_recursive_directory_iterator(::fast_io::win9x_dir_handle rh, win9x_dirent* dp)
explicit constexpr basic_win9x_recursive_directory_iterator(::fast_io::win9x_dir_handle rh, win9x_dirent *dp)
: root_handle(::std::move(rh)), entry(dp)
{}

Expand Down Expand Up @@ -348,16 +348,17 @@ inline basic_win9x_recursive_directory_iterator<StackType> &operator++(basic_win
if (prdit.entry->d_type == file_type::directory)
{
::std::size_t const native_d_namlen{prdit.entry->filename.size()};
char const *native_d_name_ptr{prdit.entry->filename.c_str()};
if ((native_d_namlen == 1 && *native_d_name_ptr == '.') ||
(native_d_namlen == 2 && *native_d_name_ptr == '.' && native_d_name_ptr[1] == u'.'))
char8_t const *native_d_name_ptr{prdit.entry->filename.c_str()};
if ((native_d_namlen == 1 && *native_d_name_ptr == u8'.') ||
(native_d_namlen == 2 && *native_d_name_ptr == u8'.' && native_d_name_ptr[1] == u8'.'))
{
continue;
}
prdit.stack.emplace_back(
win9x_dir{win9x_at_entry{prdit.stack.empty() ? prdit.root_handle : prdit.stack.back().fd.handle},
::fast_io::manipulators::basic_os_c_str_with_known_size<char>{native_d_name_ptr, native_d_namlen},
open_mode::directory}, nullptr);
::fast_io::manipulators::basic_os_c_str_with_known_size<char8_t>{native_d_name_ptr, native_d_namlen},
open_mode::directory},
nullptr);
}
return prdit;
}
Expand Down Expand Up @@ -391,19 +392,20 @@ begin(basic_win9x_recursive_directory_generator<StackType> &prg) noexcept
if (finish && prdit.entry->d_type == file_type::directory)
{
auto &ent{*prdit.entry};
char const *native_d_name_ptr{ent.filename.c_str()};
char8_t const *native_d_name_ptr{ent.filename.c_str()};
::std::size_t const native_d_namlen{ent.filename.size()};
if ((native_d_namlen == 1 && *native_d_name_ptr == '.') ||
(native_d_namlen == 2 && *native_d_name_ptr == '.' && native_d_name_ptr[1] == '.'))
if ((native_d_namlen == 1 && *native_d_name_ptr == u8'.') ||
(native_d_namlen == 2 && *native_d_name_ptr == u8'.' && native_d_name_ptr[1] == u8'.'))
{
++prdit;
}
else
{
prdit.stack.emplace_back(
win9x_dir{win9x_at_entry{prdit.root_handle},
::fast_io::manipulators::basic_os_c_str_with_known_size<char>{native_d_name_ptr, native_d_namlen},
open_mode::directory},nullptr);
::fast_io::manipulators::basic_os_c_str_with_known_size<char8_t>{native_d_name_ptr, native_d_namlen},
open_mode::directory},
nullptr);
}
}
return prdit;
Expand Down Expand Up @@ -459,25 +461,25 @@ inline win9x_recursive_directory_generator recursive(win9x_at_entry nate)
inline auto native_extension(win9x_directory_entry ent) noexcept
{
auto &et{*ent.entry};
return ::fast_io::details::find_dot_and_sep<false, char, char>(et.filename.c_str(), et.filename.size());
return ::fast_io::details::find_dot_and_sep<false, char8_t, char8_t>(et.filename.c_str(), et.filename.size());
}

inline auto native_stem(win9x_directory_entry ent) noexcept
{
auto &et{*ent.entry};
return ::fast_io::details::find_dot_and_sep<true, char, char>(et.filename.c_str(), et.filename.size());
return ::fast_io::details::find_dot_and_sep<true, char8_t, char8_t>(et.filename.c_str(), et.filename.size());
}

inline auto u8extension(win9x_directory_entry ent) noexcept
{
auto &et{*ent.entry};
return ::fast_io::details::find_dot_and_sep<false, char8_t, char>(et.filename.c_str(), et.filename.size());
return ::fast_io::details::find_dot_and_sep<false, char8_t, char8_t>(et.filename.c_str(), et.filename.size());
}

inline auto u8stem(win9x_directory_entry ent) noexcept
{
auto &et{*ent.entry};
return ::fast_io::details::find_dot_and_sep<true, char8_t, char>(et.filename.c_str(), et.filename.size());
return ::fast_io::details::find_dot_and_sep<true, char8_t, char8_t>(et.filename.c_str(), et.filename.size());
}

#ifndef __CYGWIN__
Expand Down
22 changes: 11 additions & 11 deletions include/fast_io_hosted/platforms/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ struct
struct win9x_dir_handle
{
void *handle;
::fast_io::string path;
::fast_io::u8string path;
};

namespace win32::details
Expand Down Expand Up @@ -980,7 +980,7 @@ inline win9x_dir_handle win9x_create_dir_file_at_fs_dirent_impl(win9x_dir_handle
}
}

::fast_io::string str{::fast_io::concat_fast_io(directory_handle.path, "\\", ::fast_io::mnp::code_cvt(::fast_io::mnp::os_c_str_with_known_size(filename_c_str, filename_c_str_len)))};
::fast_io::u8string str{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(directory_handle.path), u8"\\", ::fast_io::mnp::code_cvt(::fast_io::mnp::os_c_str_with_known_size(filename_c_str, filename_c_str_len)))};
auto handle{::fast_io::details::win32_create_file_impl<win32_family::ansi_9x>(str, ompm)};
return {handle, ::std::move(str)};
}
Expand All @@ -989,15 +989,15 @@ template <typename T>
requires(::fast_io::constructible_to_os_c_str<T>)
inline win9x_dir_handle win9x_create_dir_file_impl(T const &t, open_mode_perms ompm)
{
::fast_io::string path{::fast_io::concat_fast_io(::fast_io::mnp::code_cvt(t))};
::fast_io::u8string path{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(t))};
for (auto& c : path)
{
if (c == '/')
if (c == u8'/')
{
c = '\\';
c = u8'\\';
}
}
if (path.back() == '\\')
if (path.back() == u8'\\')
{
path.pop_back_unchecked();
}
Expand Down Expand Up @@ -1146,7 +1146,7 @@ inline win9x_dir_handle win9x_create_dir_file_at_impl(win9x_dir_handle directory

}

::fast_io::string str{::fast_io::concat_fast_io(directory_handle.path, "\\", ::fast_io::mnp::code_cvt(t))};
::fast_io::u8string str{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(directory_handle.path), u8"\\", ::fast_io::mnp::code_cvt(t))};
auto handle{::fast_io::details::win32_create_file_impl<win32_family::ansi_9x>(str, ompm)};
return {handle, ::std::move(str)};
}
Expand Down Expand Up @@ -1192,7 +1192,7 @@ inline void *win9x_create_file_at_fs_dirent_impl(win9x_dir_handle directory_hand
}
}

::fast_io::string str{::fast_io::concat_fast_io(directory_handle.path, "\\", ::fast_io::mnp::code_cvt(::fast_io::mnp::os_c_str_with_known_size(filename_c_str, filename_c_str_len)))};
::fast_io::u8string str{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(directory_handle.path), u8"\\", ::fast_io::mnp::code_cvt(::fast_io::mnp::os_c_str_with_known_size(filename_c_str, filename_c_str_len)))};
auto handle{::fast_io::details::win32_create_file_impl<win32_family::ansi_9x>(str, ompm)};
return handle;
}
Expand Down Expand Up @@ -1337,7 +1337,7 @@ inline void *win9x_create_file_at_impl(win9x_dir_handle directory_handle, T cons
}
}

::fast_io::string str{::fast_io::concat_fast_io(directory_handle.path, "\\", ::fast_io::mnp::code_cvt(t))};
::fast_io::u8string str{::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(directory_handle.path), u8"\\", ::fast_io::mnp::code_cvt(t))};
auto handle{::fast_io::details::win32_create_file_impl<win32_family::ansi_9x>(str, ompm)};
return handle;
}
Expand All @@ -1347,7 +1347,7 @@ inline void *win9x_create_file_at_impl(win9x_dir_handle directory_handle, T cons
struct win9x_fs_dirent
{
win9x_dir_handle handle{}; // path
::fast_io::manipulators::basic_os_c_str_with_known_size<char> filename{}; // file
::fast_io::manipulators::basic_os_c_str_with_known_size<char8_t> filename{}; // file
};

struct win9x_at_entry
Expand Down Expand Up @@ -1386,7 +1386,7 @@ class win9x_dir_io_observer
{
public:
using native_handle_type = win9x_dir_handle;
using char_type = char;
using char_type = char8_t;
using input_char_type = char_type;
using output_char_type = char_type;
native_handle_type handle{};
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_hosted/process/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ inline win32_user_process_information win32_process_create_impl(void *__restrict
auto address_begin{pszFilename};

// change nt path to dos path
auto k32_module{::fast_io::win32::GetModuleHandleA("Kernel32.dll")};
auto k32_module{::fast_io::win32::GetModuleHandleA(reinterpret_cast<char const *>(u8"Kernel32.dll"))};
if (k32_module)
{
using QueryDosDeviceA_t = ::std::uint_least32_t (*)(char const *, char *, ::std::uint_least32_t) noexcept;

// win95 may not have this function, need check (?)
auto QueryDosDeviceA_p{reinterpret_cast<QueryDosDeviceA_t>(::fast_io::win32::GetProcAddress(k32_module, "QueryDosDeviceA"))};
auto QueryDosDeviceA_p{reinterpret_cast<QueryDosDeviceA_t>(::fast_io::win32::GetProcAddress(k32_module, reinterpret_cast<char const *>(u8"QueryDosDeviceA")))};
if (QueryDosDeviceA_p)
{
if (pszFilename[0] == '\\')
Expand Down

0 comments on commit eb96c4c

Please sign in to comment.