Reactos
at master 135 lines 3.7 kB view raw
1// 2// input.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// The core formatted input functions; all of the scanf-style functions call one 7// of these functions. 8// 9#define _ALLOW_OLD_VALIDATE_MACROS 10#include <corecrt_internal_stdio_input.h> 11 12using namespace __crt_stdio_input; 13 14 15// Enclaves do not have a file system, but they do allow in-memory operations 16// from stdio. 17#ifndef _UCRT_ENCLAVE_BUILD 18 19template <typename Character> 20static int __cdecl common_vfscanf( 21 unsigned __int64 const options, 22 FILE* const stream, 23 Character const* const format, 24 _locale_t const locale, 25 va_list const arglist 26 ) throw() 27{ 28 typedef input_processor< 29 Character, 30 stream_input_adapter<Character> 31 > processor_type; 32 33 _VALIDATE_RETURN(stream != nullptr, EINVAL, EOF); 34 _VALIDATE_RETURN(format != nullptr, EINVAL, EOF); 35 36 return __acrt_lock_stream_and_call(stream, [&]() 37 { 38 _LocaleUpdate locale_update(locale); 39 40 processor_type processor( 41 stream_input_adapter<Character>(stream), 42 options, 43 format, 44 locale_update.GetLocaleT(), 45 arglist); 46 47 return processor.process(); 48 }); 49} 50 51extern "C" int __cdecl __stdio_common_vfscanf( 52 unsigned __int64 const options, 53 FILE* const stream, 54 char const* const format, 55 _locale_t const locale, 56 va_list const arglist 57 ) 58{ 59 return common_vfscanf(options, stream, format, locale, arglist); 60} 61 62extern "C" int __cdecl __stdio_common_vfwscanf( 63 unsigned __int64 const options, 64 FILE* const stream, 65 wchar_t const* const format, 66 _locale_t const locale, 67 va_list const arglist 68 ) 69{ 70 return common_vfscanf(options, stream, format, locale, arglist); 71} 72 73#endif /* _UCRT_ENCLAVE_BUILD */ 74 75 76template <typename Character> 77static int __cdecl common_vsscanf( 78 unsigned __int64 const options, 79 Character const* const buffer, 80 size_t const buffer_count, 81 Character const* const format, 82 _locale_t const locale, 83 va_list const arglist 84 ) throw() 85{ 86 typedef __acrt_stdio_char_traits<Character> char_traits; 87 88 typedef input_processor< 89 Character, 90 string_input_adapter<Character> 91 > processor_type; 92 93 _VALIDATE_RETURN(buffer != nullptr, EINVAL, EOF); 94 _VALIDATE_RETURN(format != nullptr, EINVAL, EOF); 95 96 // The number of elements to consider when scanning is the lesser of [1] the 97 // specified number of elements in the buffer or [2] the length of the string 98 // in the buffer. 99 size_t const buffer_count_for_stream = char_traits::tcsnlen(buffer, buffer_count); 100 101 _LocaleUpdate locale_update(locale); 102 103 processor_type processor( 104 string_input_adapter<Character>(buffer, buffer_count_for_stream), 105 options, 106 format, 107 locale_update.GetLocaleT(), 108 arglist); 109 110 return processor.process(); 111} 112 113extern "C" int __cdecl __stdio_common_vsscanf( 114 unsigned __int64 const options, 115 char const* const buffer, 116 size_t const buffer_count, 117 char const* const format, 118 _locale_t const locale, 119 va_list const arglist 120 ) 121{ 122 return common_vsscanf(options, buffer, buffer_count, format, locale, arglist); 123} 124 125extern "C" int __cdecl __stdio_common_vswscanf( 126 unsigned __int64 const options, 127 wchar_t const* const buffer, 128 size_t const buffer_count, 129 wchar_t const* const format, 130 _locale_t const locale, 131 va_list const arglist 132 ) 133{ 134 return common_vsscanf(options, buffer, buffer_count, format, locale, arglist); 135}