Skip to content

Commit 3b73b92

Browse files
committed
nt_at always __builtin_offsetof
1 parent a83e002 commit 3b73b92

File tree

1 file changed

+11
-37
lines changed
  • include/fast_io_hosted/filesystem

1 file changed

+11
-37
lines changed

include/fast_io_hosted/filesystem/nt_at.h

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,9 @@ inline void nt_symlinkat_impl(char16_t const *oldpath_c_str, ::std::size_t oldpa
230230
symbol_mode.CreateOptions |= 0x00000040; // file
231231
}
232232
}
233-
::std::size_t const cbReparseData{
234-
#if defined(__has_builtin)
235-
#if __has_builtin(__builtin_offsetof)
236-
#if defined(_MSC_VER) && defined(__clang__)
237-
__builtin_offsetof(SymbolicLinkReparseBuffer.PathBuffer, reparse_data_buffer)
238-
#else
239-
__builtin_offsetof(reparse_data_buffer, SymbolicLinkReparseBuffer.PathBuffer)
240-
#endif
241-
#else
242-
offsetof(reparse_data_buffer, SymbolicLinkReparseBuffer.PathBuffer)
243-
#endif
244-
#else
245-
offsetof(reparse_data_buffer, SymbolicLinkReparseBuffer.PathBuffer)
246-
#endif
247-
+
248-
oldpath_real_size * sizeof(char16_t) * 2};
233+
constexpr ::std::size_t pathbufferoffset{
234+
__builtin_offsetof(reparse_data_buffer, SymbolicLinkReparseBuffer.PathBuffer)};
235+
::std::size_t const cbReparseData{pathbufferoffset + oldpath_real_size * sizeof(char16_t) * 2};
249236

250237
using reparse_data_buffer_may_alias_ptr
251238
#if __has_cpp_attribute(__gnu__::__may_alias__)
@@ -260,21 +247,8 @@ inline void nt_symlinkat_impl(char16_t const *oldpath_c_str, ::std::size_t oldpa
260247
auto pBufTail{reinterpret_cast<char16_t *>(pReparseData->SymbolicLinkReparseBuffer.PathBuffer)};
261248

262249
pReparseData->ReparseTag = 0xA000000CL; // IO_REPARSE_TAG_SYMLINK
263-
pReparseData->ReparseDataLength = static_cast<::std::uint_least16_t>(cbReparseData -
264-
#if defined(__has_builtin)
265-
#if __has_builtin(__builtin_offsetof)
266-
#if defined(_MSC_VER) && defined(__clang__)
267-
__builtin_offsetof(GenericReparseBuffer, reparse_data_buffer)
268-
#else
269-
__builtin_offsetof(reparse_data_buffer, GenericReparseBuffer)
270-
#endif
271-
#else
272-
offsetof(reparse_data_buffer, GenericReparseBuffer)
273-
#endif
274-
#else
275-
offsetof(reparse_data_buffer, GenericReparseBuffer)
276-
#endif
277-
);
250+
constexpr ::std::size_t reparsebufferoffset{__builtin_offsetof(reparse_data_buffer, GenericReparseBuffer)};
251+
pReparseData->ReparseDataLength = static_cast<::std::uint_least16_t>(cbReparseData - reparsebufferoffset);
278252
pReparseData->Reserved = 0;
279253

280254
pReparseData->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
@@ -383,11 +357,11 @@ inline void nt_linkat_impl(void *olddirhd, char16_t const *oldpath_c_str, ::std:
383357

384358
if ((flags & nt_at_flags::empty_path) == nt_at_flags::empty_path && oldpath_size == 0)
385359
{
386-
file = ::fast_io::basic_nt_family_io_observer < zw ? nt_family::zw : nt_family::nt, char > {olddirhd};
360+
file = ::fast_io::basic_nt_family_io_observer<zw ? nt_family::zw : nt_family::nt, char>{olddirhd};
387361
}
388362
else
389363
{
390-
basic_file = ::fast_io::basic_nt_family_file < zw ? nt_family::zw : nt_family::nt, char > {nt_call_callback(olddirhd, oldpath_c_str, oldpath_size, nt_create_callback<zw>{md})};
364+
basic_file = ::fast_io::basic_nt_family_file<zw ? nt_family::zw : nt_family::nt, char>{nt_call_callback(olddirhd, oldpath_c_str, oldpath_size, nt_create_callback<zw>{md})};
391365
file = basic_file;
392366
}
393367

@@ -478,7 +452,7 @@ template <nt_family family, ::fast_io::details::posix_api_1x dsp, typename path_
478452
inline auto nt_deal_with1x(void *dir_handle, path_type const &path, Args... args)
479453
{
480454
return nt_api_common(
481-
path, [&](char16_t const *path_c_str, ::std::size_t path_size) { return nt1x_api_dispatcher<family == nt_family::zw, dsp>(dir_handle, path_c_str, path_size, args...); });
455+
path, [&](char16_t const *path_c_str, ::std::size_t path_size) { return nt1x_api_dispatcher < family == nt_family::zw, dsp > (dir_handle, path_c_str, path_size, args...); });
482456
}
483457

484458
template <nt_family family, ::fast_io::details::posix_api_12 dsp, ::fast_io::constructible_to_os_c_str old_path_type,
@@ -489,7 +463,7 @@ inline auto nt_deal_with12(old_path_type const &oldpath, void *newdirfd, new_pat
489463
oldpath,
490464
[&](char16_t const *oldpath_c_str, ::std::size_t oldpath_size) {
491465
return nt_api_common(
492-
newpath, [&](char16_t const *newpath_c_str, ::std::size_t newpath_size) { return nt12_api_dispatcher<family == nt_family::zw, dsp>(oldpath_c_str, oldpath_size, newdirfd, newpath_c_str, newpath_size); });
466+
newpath, [&](char16_t const *newpath_c_str, ::std::size_t newpath_size) { return nt12_api_dispatcher < family == nt_family::zw, dsp > (oldpath_c_str, oldpath_size, newdirfd, newpath_c_str, newpath_size); });
493467
});
494468
}
495469

@@ -500,8 +474,8 @@ inline auto nt_deal_with22(void *olddirhd, oldpath_type const &oldpath, void *ne
500474
[&](char16_t const *oldpath_c_str, ::std::size_t oldpath_size) {
501475
return nt_api_common(newpath,
502476
[&](char16_t const *newpath_c_str, ::std::size_t newpath_size) {
503-
return nt22_api_dispatcher<family == nt_family::zw, dsp>(olddirhd, oldpath_c_str, oldpath_size, newdirhd,
504-
newpath_c_str, newpath_size, args...);
477+
return nt22_api_dispatcher < family == nt_family::zw, dsp > (olddirhd, oldpath_c_str, oldpath_size, newdirhd,
478+
newpath_c_str, newpath_size, args...);
505479
});
506480
});
507481
}

0 commit comments

Comments
 (0)