Skip to content

Commit 251b992

Browse files
authored
fix (#1181)
* fix * fix * fix * fix dos
1 parent b0b2e1d commit 251b992

File tree

21 files changed

+207
-82
lines changed

21 files changed

+207
-82
lines changed

include/fast_io_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <bit>
1313
#include <limits>
1414
#include <cstdint>
15+
#include <version>
1516

1617
#if __cpp_lib_three_way_comparison >= 201907L
1718
#include <compare>

include/fast_io_core_impl/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ inline constexpr T compile_pow2{::fast_io::details::compile_pow_n<T, 2, pow>};
467467

468468

469469
inline constexpr bool is_wasi_environment{
470-
#if __wasi__
470+
#ifdef __wasi__
471471
true
472472
#endif
473473
};

include/fast_io_freestanding_impl/serializations/lebe.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ inline constexpr auto iec559_lebe_put(T t)
181181
}
182182
else
183183
{
184-
#if __STDCPP_FLOAT32_T__
184+
#ifdef __STDCPP_FLOAT32_T__
185185
return ::fast_io::manipulators::lebe_put<en, 32>(
186186
::std::bit_cast<::std::uint_least32_t>(static_cast<_Float32>(t)));
187187
#else
@@ -198,7 +198,7 @@ inline constexpr auto iec559_lebe_put(T t)
198198
}
199199
else
200200
{
201-
#if __STDCPP_FLOAT64_T__
201+
#ifdef __STDCPP_FLOAT64_T__
202202
return ::fast_io::manipulators::lebe_put<en, 64>(
203203
::std::bit_cast<::std::uint_least64_t>(static_cast<_Float64>(t)));
204204
#else
@@ -208,7 +208,7 @@ inline constexpr auto iec559_lebe_put(T t)
208208
}
209209
else if constexpr (::std::same_as<nocvref, long double>)
210210
{
211-
#if __STDCPP_FLOAT128_T__
211+
#ifdef __STDCPP_FLOAT128_T__
212212
using proxy_type = ::fast_io::details::pesudo_int128type;
213213
return ::fast_io::manipulators::basic_lebe_get_put<en, basic_lebe_put_integral<128, proxy_type>>{
214214
{::std::bit_cast<::fast_io::details::pesudo_int128type>(static_cast<_Float128>(t))}};
@@ -480,7 +480,7 @@ scan_precise_reserve_define_lebe_float_get_impl(char_type const *iter, flttypef
480480
}
481481
else
482482
{
483-
#if __STDCPP_FLOAT32_T__
483+
#ifdef __STDCPP_FLOAT32_T__
484484
t = static_cast<flttypef>(::std::bit_cast<_Float32>(temp));
485485
#else
486486
static_assert(isiec559, "float is not iec60559");
@@ -495,7 +495,7 @@ scan_precise_reserve_define_lebe_float_get_impl(char_type const *iter, flttypef
495495
}
496496
else
497497
{
498-
#if __STDCPP_FLOAT64_T__
498+
#ifdef __STDCPP_FLOAT64_T__
499499
t = static_cast<flttypef>(::std::bit_cast<_Float64>(temp));
500500
#else
501501
static_assert(isiec559, "double is not iec60559");
@@ -504,7 +504,7 @@ scan_precise_reserve_define_lebe_float_get_impl(char_type const *iter, flttypef
504504
}
505505
else if constexpr (::std::same_as<flttype, long double>)
506506
{
507-
#if __STDCPP_FLOAT128_T__
507+
#ifdef __STDCPP_FLOAT128_T__
508508
t = static_cast<flttypef>(::std::bit_cast<_Float128>(temp));
509509
#else
510510
static_assert(sizeof(double) != sizeof(long) && isiec559,

include/fast_io_freestanding_impl/transcoders/transcoder_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class basic_transcoder_file : public transcoder_io_observer
234234
other.transhandle = nullptr;
235235
return *this;
236236
}
237-
inline constexpr void close() noexcept
237+
inline constexpr void close()
238238
{
239239
this->transhandle->destroy();
240240
this->transhandle = nullptr;

include/fast_io_hosted/filesystem/dos_at.h

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -111,65 +111,16 @@ inline constexpr dos_at_flags &operator^=(dos_at_flags &x, dos_at_flags y) noexc
111111
namespace details
112112
{
113113

114-
struct my_dos_concat_path_common_result
115-
{
116-
bool failed{};
117-
::fast_io::tlc::string path = ::fast_io::tlc::string();
118-
};
119-
120-
inline my_dos_concat_path_common_result my_dos_concat_path_common(int dirfd, char const *pathname) noexcept
121-
{
122-
if (dirfd == -100)
123-
{
124-
return {false, ::fast_io::tlc::string(::fast_io::mnp::os_c_str(pathname))};
125-
}
126-
else
127-
{
128-
auto pathname_cstr{::fast_io::noexcept_call(::__get_fd_name, dirfd)};
129-
if (pathname_cstr == nullptr) [[unlikely]]
130-
{
131-
return {true};
132-
}
133-
134-
// check vaildity
135-
auto const sz{::fast_io::cstr_len(pathname)};
136-
137-
if (sz > 255) [[unlikely]]
138-
{
139-
return {true};
140-
}
141-
142-
if (::fast_io::details::is_invalid_dos_filename_with_size(pathname, sz)) [[unlikely]]
143-
{
144-
return {true};
145-
}
146-
147-
// concat
148-
return {false, ::fast_io::tlc::concat_fast_io_tlc(::fast_io::mnp::os_c_str(pathname_cstr), ::fast_io::mnp::chvw(u8'\\'), para_pathname)};
149-
}
150-
}
151-
152-
template <bool always_terminate = true>
153-
inline ::fast_io::tlc::string my_dos_concat_path(int dirfd, char const *pathname) noexcept(always_terminate)
154-
{
155-
auto [failed, path] = ::fast_io::details::my_dos_concat_path_common(dirfd, pathname);
156-
if (failed) [[unlikely]]
157-
{
158-
::fast_io::system_call_throw_error<always_terminate>(-1);
159-
}
160-
return ::std::move(path);
161-
}
162-
163114
inline void dos_renameat_impl(int olddirfd, char const *oldpath, int newdirfd, char const *newpath)
164115
{
165-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_rename(::fast_io::details::my_dos_concat_path(olddirfd, oldpath).c_str(),
166-
::fast_io::details::my_dos_concat_path(newdirfd, newpath).c_str()));
116+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_rename(::fast_io::details::my_dos_concat_tlc_path(olddirfd, oldpath).c_str(),
117+
::fast_io::details::my_dos_concat_tlc_path(newdirfd, newpath).c_str()));
167118
}
168119

169120
inline void dos_linkat_impl(int olddirfd, char const *oldpath, int newdirfd, char const *newpath)
170121
{
171-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_link(::fast_io::details::my_dos_concat_path(olddirfd, oldpath).c_str(),
172-
::fast_io::details::my_dos_concat_path(newdirfd, newpath).c_str()));
122+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_link(::fast_io::details::my_dos_concat_tlc_path(olddirfd, oldpath).c_str(),
123+
::fast_io::details::my_dos_concat_tlc_path(newdirfd, newpath).c_str()));
173124
}
174125

175126
template <posix_api_22 dsp, typename... Args>
@@ -187,7 +138,7 @@ inline auto dos22_api_dispatcher(int olddirfd, char const *oldpath, int newdirfd
187138

188139
inline void dos_symlinkat_impl(char const *oldpath, int newdirfd, char const *newpath)
189140
{
190-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_symlink(oldpath, ::fast_io::details::my_dos_concat_path(newdirfd, newpath).c_str()));
141+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_symlink(oldpath, ::fast_io::details::my_dos_concat_tlc_path(newdirfd, newpath).c_str()));
191142
}
192143

193144
template <posix_api_12 dsp, typename... Args>
@@ -201,37 +152,37 @@ inline auto dos12_api_dispatcher(char const *oldpath, int newdirfd, char const *
201152

202153
inline void dos_faccessat_impl(int dirfd, char const *pathname, int flags)
203154
{
204-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_access(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(), flags));
155+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_access(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(), flags));
205156
}
206157

207158
inline void dos_fchownat_impl(int dirfd, char const *pathname, uintmax_t owner, uintmax_t group)
208159
{
209160
// chown does nothing under MS-DOS, so just check is_valid filename
210-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_chown(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(),
161+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_chown(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(),
211162
static_cast<int>(owner), static_cast<int>(group)));
212163
}
213164

214165
inline void dos_fchmodat_impl(int dirfd, char const *pathname, mode_t mode)
215166
{
216-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_chmod(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(), mode));
167+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_chmod(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(), mode));
217168
}
218169

219170
inline posix_file_status dos_fstatat_impl(int dirfd, char const *pathname)
220171
{
221172
struct stat buf;
222173

223-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_stat(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(), __builtin_addressof(buf)));
174+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_stat(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(), __builtin_addressof(buf)));
224175
return ::fast_io::details::struct_stat_to_posix_file_status(buf);
225176
}
226177

227178
inline void dos_mkdirat_impl(int dirfd, char const *pathname, mode_t mode)
228179
{
229-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_mkdir(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(), mode));
180+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_mkdir(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(), mode));
230181
}
231182

232183
inline void dos_unlinkat_impl(int dirfd, char const *pathname)
233184
{
234-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_unlink(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str()));
185+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_unlink(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str()));
235186
}
236187

237188
inline constexpr ::std::time_t unix_timestamp_to_time_t(unix_timestamp stmp) noexcept
@@ -271,7 +222,7 @@ inline void dos_utimensat_impl(int dirfd, char const *pathname, unix_timestamp_o
271222
::fast_io::details::unix_timestamp_to_time_t(last_modification_time),
272223
};
273224

274-
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_utime(::fast_io::details::my_dos_concat_path(dirfd, pathname).c_str(), __builtin_addressof(ts)));
225+
::fast_io::system_call_throw_error(::fast_io::posix::my_dos_utime(::fast_io::details::my_dos_concat_tlc_path(dirfd, pathname).c_str(), __builtin_addressof(ts)));
275226
}
276227

277228
template <posix_api_1x dsp, typename... Args>

include/fast_io_hosted/platforms/posix.h

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@
6262
namespace fast_io
6363
{
6464

65+
#if ((!defined(_WIN32) || defined(__WINE__)) || defined(__CYGWIN__))
66+
namespace posix
67+
{
68+
#if defined(__DARWIN_C_LEVEL) || defined(__MSDOS__)
69+
extern int libc_ioctl(int fd, unsigned long request, ...) noexcept __asm__("_ioctl");
70+
#else
71+
extern int libc_ioctl(int fd, unsigned long request, ...) noexcept __asm__("ioctl");
72+
#endif
73+
} // namespace posix
74+
#endif
75+
6576
enum class posix_family
6677
{
6778
api,
@@ -836,13 +847,76 @@ extern int my_posix_open_noexcept(char const *pathname, int flags, mode_t mode)
836847

837848
#if defined(__MSDOS__)
838849

839-
template <bool always_terminate>
840-
inline ::fast_io::tlc::string my_dos_concat_path(int, char const *) noexcept(always_terminate);
850+
using dos_path_tlc_string = ::fast_io::containers::basic_string<char, ::fast_io::native_thread_local_allocator>;
851+
852+
template <typename... Args>
853+
constexpr inline dos_path_tlc_string concat_dos_path_tlc_string(Args &&...args)
854+
{
855+
constexpr bool type_error{::fast_io::operations::defines::print_freestanding_okay<::fast_io::details::dummy_buffer_output_stream<char>, Args...>};
856+
if constexpr (type_error)
857+
{
858+
return ::fast_io::basic_general_concat<false, char, dos_path_tlc_string>(::fast_io::io_print_forward<char>(::fast_io::io_print_alias(args))...);
859+
}
860+
else
861+
{
862+
static_assert(type_error, "some types are not printable, so we cannot concat dos_path_tlc_string");
863+
return {};
864+
}
865+
}
866+
867+
struct my_dos_concat_tlc_path_common_result
868+
{
869+
bool failed{};
870+
dos_path_tlc_string path{};
871+
};
872+
873+
inline constexpr my_dos_concat_tlc_path_common_result my_dos_concat_tlc_path_common(int dirfd, char const *pathname) noexcept
874+
{
875+
if (dirfd == -100)
876+
{
877+
return {false, dos_path_tlc_string{::fast_io::mnp::os_c_str(pathname)}};
878+
}
879+
else
880+
{
881+
auto fd_pathname_cstr{::fast_io::noexcept_call(::__get_fd_name, dirfd)};
882+
if (fd_pathname_cstr == nullptr) [[unlikely]]
883+
{
884+
return {true};
885+
}
886+
887+
// check vaildity
888+
auto const sz{::fast_io::cstr_len(pathname)};
889+
890+
if (sz > 255) [[unlikely]]
891+
{
892+
return {true};
893+
}
894+
895+
if (::fast_io::details::is_invalid_dos_filename_with_size(pathname, sz)) [[unlikely]]
896+
{
897+
return {true};
898+
}
899+
900+
// concat
901+
return {false, concat_dos_path_tlc_string(::fast_io::mnp::os_c_str(fd_pathname_cstr), ::fast_io::mnp::chvw('\\'), ::fast_io::mnp::os_c_str(pathname))};
902+
}
903+
}
904+
905+
template <bool always_terminate = true>
906+
inline constexpr dos_path_tlc_string my_dos_concat_tlc_path(int dirfd, char const *pathname) noexcept(always_terminate)
907+
{
908+
auto [failed, path]{my_dos_concat_tlc_path_common(dirfd, pathname)};
909+
if (failed) [[unlikely]]
910+
{
911+
::fast_io::system_call_throw_error<always_terminate>(-1);
912+
}
913+
return path;
914+
}
841915

842916
template <bool always_terminate = false>
843917
inline int my_posix_openat(int dirfd, char const *pathname, int flags, mode_t mode)
844918
{
845-
int fd{::fast_io::details::my_posix_open_noexcept(::fast_io::details::my_dos_concat_path<always_terminate>(dirfd, pathname).c_str(), flags, mode)};
919+
int fd{::fast_io::details::my_posix_open_noexcept(my_dos_concat_tlc_path<always_terminate>(dirfd, pathname).c_str(), flags, mode)};
846920
system_call_throw_error<always_terminate>(fd);
847921
return fd;
848922
}

include/fast_io_hosted/platforms/posix_mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class posix_memory_map_file
291291
{
292292
return address_begin[pos];
293293
}
294-
inline void close() noexcept
294+
inline void close()
295295
{
296296
if (this->address_begin != MAP_FAILED) [[likely]]
297297
{

include/fast_io_hosted/platforms/win32.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ class win32_9xa_dir_io_observer
12341234
{
12351235
return handle;
12361236
}
1237-
inline explicit operator bool() const noexcept
1237+
inline explicit constexpr operator bool() const noexcept
12381238
{
12391239
return !handle.path.empty();
12401240
}
@@ -1244,6 +1244,7 @@ class win32_9xa_dir_io_observer
12441244
return temp;
12451245
}
12461246
};
1247+
12471248
inline constexpr bool operator==(win32_9xa_dir_io_observer const &a,
12481249
win32_9xa_dir_io_observer const &b) noexcept
12491250
{
@@ -1310,11 +1311,11 @@ class win32_9xa_dir_file : public win32_9xa_dir_io_observer
13101311
}
13111312
this->handle = ::std::move(newhandle);
13121313
}
1313-
inline void close() noexcept
1314+
inline void close()
13141315
{
13151316
if (*this) [[likely]]
13161317
{
1317-
::fast_io::win32::details::close_win32_9xa_dir_handle(this->handle);
1318+
::fast_io::win32::details::close_win32_9xa_dir_handle<true>(this->handle);
13181319
}
13191320
}
13201321

include/fast_io_hosted/timeutil/time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace fast_io
66
namespace posix
77
{
88
#if !defined(_WIN32) && !defined(__AVR__) && !defined(__MSDOS__)
9-
#ifdef __DARWIN_C_LEVEL
9+
#if defined(__DARWIN_C_LEVEL)
1010
extern int libc_clock_getres(clockid_t clk_id, struct timespec *tp) noexcept __asm__("_clock_getres");
1111
extern int libc_clock_settime(clockid_t clk_id, struct timespec const *tp) noexcept __asm__("_clock_settime");
1212
extern int libc_clock_gettime(clockid_t clk_id, struct timespec *tp) noexcept __asm__("_clock_gettime");
1313
#else
14-
#if _REDIR_TIME64
14+
#if defined(_REDIR_TIME64)
1515
extern int libc_clock_getres(clockid_t clk_id, struct timespec *tp) noexcept __asm__("__clock_getres64");
1616
extern int libc_clock_settime(clockid_t clk_id, struct timespec const *tp) noexcept __asm__("__clock_settime64");
1717
extern int libc_clock_gettime(clockid_t clk_id, struct timespec *tp) noexcept __asm__("__clock_gettime64");

include/fast_io_hosted/white_hole/white_hole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ inline int my_random_entropy(int fd) noexcept
4949
return 0;
5050
}
5151
#else
52-
if (::fast_io::posix::ioctl(fd, RNDGETENTCNT, __builtin_addressof(ent)) != 0)
52+
if (::fast_io::posix::libc_ioctl(fd, RNDGETENTCNT, __builtin_addressof(ent)) != 0)
5353
{
5454
return 0;
5555
}

0 commit comments

Comments
 (0)