mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 21:11:54 +00:00
[UCRT] Import Microsoft.Windows.SDK.CRTSource version 10.0.22621.3
Imported from https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource/10.0.22621.3 License: MIT
This commit is contained in:
parent
f1b60c66f0
commit
04e0dc4a7a
568 changed files with 115483 additions and 0 deletions
60
sdk/lib/ucrt/stdio/rewind.cpp
Normal file
60
sdk/lib/ucrt/stdio/rewind.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// rewind.cpp
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Defines rewind(), which rewinds a stream.
|
||||
//
|
||||
#include <corecrt_internal_stdio.h>
|
||||
#include <corecrt_internal_ptd_propagation.h>
|
||||
|
||||
|
||||
|
||||
// Rewinds a stream back to the beginning, if the stream supports seeking. The
|
||||
// stream is flushed and errors are cleared before the rewind.
|
||||
static void __cdecl _rewind_internal(FILE* const public_stream, __crt_cached_ptd_host& ptd)
|
||||
{
|
||||
__crt_stdio_stream const stream(public_stream);
|
||||
|
||||
_UCRT_VALIDATE_RETURN_VOID(ptd, stream.valid(), EINVAL);
|
||||
|
||||
int const fh = _fileno(stream.public_stream());
|
||||
|
||||
_lock_file(stream.public_stream());
|
||||
__try
|
||||
{
|
||||
// Flush the streeam, reset the error state, and seek back to the
|
||||
// beginning:
|
||||
__acrt_stdio_flush_nolock(stream.public_stream(), ptd);
|
||||
// If the stream is opened in update mode and is currently in use for reading,
|
||||
// the buffer must be abandoned to ensure consistency when transitioning from
|
||||
// reading to writing.
|
||||
// __acrt_stdio_flush_nolock will not reset the buffer when _IOWRITE flag
|
||||
// is not set.
|
||||
__acrt_stdio_reset_buffer(stream);
|
||||
|
||||
|
||||
stream.unset_flags(_IOERROR | _IOEOF);
|
||||
_osfile_safe(fh) &= ~(FEOFLAG);
|
||||
|
||||
if (stream.has_all_of(_IOUPDATE))
|
||||
{
|
||||
stream.unset_flags(_IOREAD | _IOWRITE);
|
||||
}
|
||||
|
||||
if (_lseek_internal(fh, 0, 0, ptd) == -1)
|
||||
{
|
||||
stream.set_flags(_IOERROR);
|
||||
}
|
||||
}
|
||||
__finally
|
||||
{
|
||||
_unlock_file(stream.public_stream());
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void __cdecl rewind(FILE* const public_stream)
|
||||
{
|
||||
__crt_cached_ptd_host ptd;
|
||||
_rewind_internal(public_stream, ptd);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue