|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #include <corecrt_internal_stdio.h>
|
| #include <corecrt_internal_ptd_propagation.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| static int __cdecl _fclose_nolock_internal(FILE* const public_stream, __crt_cached_ptd_host& ptd)
|
| {
|
| __crt_stdio_stream const stream(public_stream);
|
|
|
| _UCRT_VALIDATE_RETURN(ptd, stream.valid(), EINVAL, EOF);
|
|
|
| int result = EOF;
|
|
|
| if (stream.is_in_use())
|
| {
|
| result = __acrt_stdio_flush_nolock(stream.public_stream(), ptd);
|
| __acrt_stdio_free_buffer_nolock(stream.public_stream());
|
|
|
| if (_close_internal(_fileno(stream.public_stream()), ptd) < 0)
|
| {
|
| result = EOF;
|
| }
|
| else if (stream->_tmpfname != nullptr)
|
| {
|
| _free_crt(stream->_tmpfname);
|
| stream->_tmpfname = nullptr;
|
| }
|
| }
|
|
|
| __acrt_stdio_free_stream(stream);
|
|
|
| return result;
|
| }
|
|
|
| extern "C" int __cdecl _fclose_nolock(FILE* const public_stream)
|
| {
|
| __crt_cached_ptd_host ptd;
|
| return _fclose_nolock_internal(public_stream, ptd);
|
| }
|
|
|
| static int __cdecl _fclose_internal(FILE* const public_stream, __crt_cached_ptd_host& ptd)
|
| {
|
| __crt_stdio_stream const stream(public_stream);
|
|
|
| _UCRT_VALIDATE_RETURN(ptd, stream.valid(), EINVAL, EOF);
|
|
|
|
|
|
|
|
|
| if (stream.is_string_backed())
|
| {
|
| __acrt_stdio_free_stream(stream);
|
| return EOF;
|
| }
|
|
|
| int return_value = 0;
|
|
|
| _lock_file(stream.public_stream());
|
| __try
|
| {
|
| return_value = _fclose_nolock_internal(stream.public_stream(), ptd);
|
| }
|
| __finally
|
| {
|
| _unlock_file(stream.public_stream());
|
| }
|
|
|
| return return_value;
|
| }
|
|
|
| extern "C" int __cdecl fclose(FILE* const public_stream)
|
| {
|
| __crt_cached_ptd_host ptd;
|
| return _fclose_internal(public_stream, ptd);
|
| }
|
|
|