Reactos
at master 43 lines 1.2 kB view raw
1 2// 3// _getbuf.cpp 4// 5// Copyright (c) Microsoft Corporation. All rights reserved. 6// 7// Defines __acrt_stdio_allocate_buffer_nolock(), which allocates a buffer for a stream. 8// 9#include <corecrt_internal_stdio.h> 10 11 12 13// Allocates a buffer for the provided stream. This function assumes that the 14// caller has already checked to ensure that the stream does not already have a 15// buffer. 16extern "C" void __cdecl __acrt_stdio_allocate_buffer_nolock(FILE* const public_stream) 17{ 18 _ASSERTE(public_stream != nullptr); 19 20 __crt_stdio_stream const stream(public_stream); 21 22 #ifndef CRTDLL 23 ++_cflush; // Force the library pre-termination procedure to run 24 #endif 25 26 // Try to get a big buffer: 27 stream->_base = _calloc_crt_t(char, _INTERNAL_BUFSIZ).detach(); 28 if (stream->_base != nullptr) 29 { 30 stream.set_flags(_IOBUFFER_CRT); 31 stream->_bufsiz = _INTERNAL_BUFSIZ; 32 } 33 // If we couldn't get a big buffer, use single character buffering: 34 else 35 { 36 stream.set_flags(_IOBUFFER_NONE); 37 stream->_base = reinterpret_cast<char *>(&stream->_charbuf); 38 stream->_bufsiz = 2; 39 } 40 41 stream->_ptr = stream->_base; 42 stream->_cnt = 0; 43}