Skip to content

Commit 03529ce

Browse files
committed
Add support for O_DSYNC and O_RSYNC in POSIX and platform headers
- Introduced `dsync` and `rsync` modes in `open_mode` enumeration. - Updated `calculate_posix_open_mode` to handle `O_DSYNC` and `O_RSYNC` flags. - Refactored directory iterator implementations to use `noexcept_call` for safer error handling. - Adjusted conditional checks in NT and Win32 headers for consistency in handling `follow` mode.
1 parent 1bcc7e5 commit 03529ce

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

include/fast_io_core_impl/mode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ enum class open_mode : ::std::uint_least64_t
287287
// *POSIX O_TRUNC
288288
tty_init = static_cast<::std::uint_least64_t>(1) << 32,
289289
// POSIX O_TTY_INIT
290+
dsync = static_cast<::std::uint_least64_t>(1) << 33,
291+
// POSIX O_DSYNC
292+
rsync = static_cast<::std::uint_least64_t>(1) << 34,
293+
// POSIX O_RSYNC
290294
};
291295

292296
inline constexpr open_mode operator&(open_mode x, open_mode y) noexcept

include/fast_io_hosted/filesystem/posix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ inline posix_directory_iterator &operator++(posix_directory_iterator &pdit)
332332
To fix: avoid setting errno
333333
*/
334334
errno = 0; // [tls]
335-
auto entry{readdir(pdit.dirp)};
335+
auto entry{::fast_io::noexcept_call(::readdir, pdit.dirp)};
336336
auto en{errno};
337337
if (entry == nullptr && en)
338338
{
@@ -357,7 +357,7 @@ inline posix_directory_iterator &operator++(posix_directory_iterator &pdit)
357357
inline posix_directory_iterator begin(posix_directory_generator const &pdg)
358358
{
359359
auto dirp{pdg.dir_fl.dirp};
360-
::rewinddir(dirp);
360+
::fast_io::noexcept_call(::rewinddir, dirp);
361361
posix_directory_iterator pdit{dirp};
362362
++pdit;
363363
return pdit;
@@ -433,7 +433,7 @@ operator++(basic_posix_recursive_directory_iterator<StackType> &prdit)
433433
errno = 0;
434434
if (prdit.stack.empty())
435435
{
436-
auto entry{readdir(prdit.dirp)};
436+
auto entry{::fast_io::noexcept_call(::readdir, prdit.dirp)};
437437
if (entry == nullptr)
438438
{
439439
auto en{errno};
@@ -448,7 +448,7 @@ operator++(basic_posix_recursive_directory_iterator<StackType> &prdit)
448448
}
449449
else
450450
{
451-
auto entry = readdir(prdit.stack.back().dirp);
451+
auto entry = ::fast_io::noexcept_call(::readdir, prdit.stack.back().dirp);
452452
if (entry == nullptr)
453453
{
454454
auto en{errno};
@@ -515,7 +515,7 @@ inline basic_posix_recursive_directory_iterator<StackType>
515515
begin(basic_posix_recursive_directory_generator<StackType> const &pdg)
516516
{
517517
auto dirp{pdg.dir_fl.dirp};
518-
::rewinddir(dirp);
518+
::fast_io::noexcept_call(::rewinddir, dirp);
519519
basic_posix_recursive_directory_iterator<StackType> pdit{dirp};
520520
++pdit;
521521
return pdit;

include/fast_io_hosted/platforms/nt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ inline constexpr nt_open_mode calculate_nt_open_mode(open_mode_perms ompm) noexc
220220
{
221221
mode.CreateOptions |= 0x00000002; // FILE_WRITE_THROUGH
222222
}
223-
if ((value & open_mode::follow) != open_mode::none)
223+
if ((value & open_mode::follow) == open_mode::none)
224224
{
225225
mode.CreateOptions |= 0x00200000; // FILE_FLAG_OPEN_REPARSE_POINT => FILE_OPEN_REPARSE_POINT (0x00200000)
226226
}

include/fast_io_hosted/platforms/posix.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ inline constexpr int calculate_posix_open_mode(open_mode value) noexcept
227227
mode |= O_SYNC;
228228
}
229229
#endif
230+
#ifdef O_DSYNC
231+
if ((value & open_mode::dsync) != open_mode::none)
232+
{
233+
mode |= O_DSYNC;
234+
}
235+
#endif
236+
#ifdef O_RSYNC
237+
if ((value & open_mode::rsync) != open_mode::none)
238+
{
239+
mode |= O_RSYNC;
240+
}
241+
#endif
230242
#ifdef O_TTY_INIT
231243
if ((value & open_mode::tty_init) != open_mode::none)
232244
{

include/fast_io_hosted/platforms/win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ inline constexpr win32_open_mode calculate_win32_open_mode(open_mode_perms ompm)
406406
{
407407
mode.dwFlagsAndAttributes |= 0x40000000; // FILE_FLAG_OVERLAPPED
408408
}
409-
if ((value & open_mode::follow) != open_mode::none)
409+
if ((value & open_mode::follow) == open_mode::none)
410410
{
411411
mode.dwFlagsAndAttributes |= 0x00200000; // FILE_FLAG_OPEN_REPARSE_POINT
412412
}

0 commit comments

Comments
 (0)