ReactOS 0.4.16-dev-1063-gd722e70
gets.cpp File Reference
Include dependency graph for gets.cpp:

Go to the source code of this file.

Functions

template<typename Character >
 _Success_ (return !=nullptr) static Character *__cdecl common_gets(_Out_writes_z_(result_size_in_characters) Character *const result
 
_In_ size_t const _In_ bool const return_early_if_eof_is_first throw ()
 
char *__cdecl gets_s (char *const result, size_t const result_size_in_characters)
 
wchar_t *__cdecl _getws_s (wchar_t *const result, size_t const result_size_in_characters)
 
char *__cdecl gets (char *const result)
 
wchar_t *__cdecl _getws (wchar_t *const result)
 

Variables

_In_ size_t const result_size_in_characters
 

Function Documentation

◆ _getws()

wchar_t *__cdecl _getws ( wchar_t *const  result)

Definition at line 146 of file gets.cpp.

147{
148 return common_gets(result, _CRT_UNBOUNDED_BUFFER_SIZE, true);
149}
#define _CRT_UNBOUNDED_BUFFER_SIZE
GLuint64EXT * result
Definition: glext.h:11304

◆ _getws_s()

wchar_t *__cdecl _getws_s ( wchar_t *const  result,
size_t const  result_size_in_characters 
)

Definition at line 129 of file gets.cpp.

130{
131 return common_gets(result, result_size_in_characters, false);
132}
_In_ size_t const result_size_in_characters
Definition: gets.cpp:35

◆ _Success_()

template<typename Character >
_Success_ ( return = nullptr) const

◆ gets()

◆ gets_s()

char *__cdecl gets_s ( char *const  result,
size_t const  result_size_in_characters 
)

Definition at line 124 of file gets.cpp.

125{
126 return common_gets(result, result_size_in_characters, false);
127}

◆ throw()

_In_ size_t const _In_ bool const return_early_if_eof_is_first throw ( )

Definition at line 37 of file gets.cpp.

38{
39 typedef __acrt_stdio_char_traits<Character> stdio_traits;
40
41 _VALIDATE_RETURN(result != nullptr, EINVAL, nullptr);
43
44 Character* return_value = result;
45
47 __try
48 {
49 if (!stdio_traits::validate_stream_is_ansi_if_required(stdin))
50 {
51 return_value = nullptr;
52 __leave;
53 }
54
55 // Special case: if the first character is EOF, treat it specially if
56 // we were asked to do so:
57 typename stdio_traits::int_type c = stdio_traits::getc_nolock(stdin);
58 if (c == stdio_traits::eof)
59 {
60 return_value = nullptr;
61 if (return_early_if_eof_is_first)
62 __leave;
63 }
64
65 // For the insecure version, we do no buffer size check and no debug fill:
67 {
68#pragma warning(push)
69#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_HIGH_PRIORITY) // 26015 - knowingly unsafe
70 Character* result_it = result;
71 while (c != '\n' && c != stdio_traits::eof)
72 {
73 *result_it++ = static_cast<Character>(c);
74 c = stdio_traits::getc_nolock(stdin);
75 }
76 *result_it = '\0';
77#pragma warning(pop)
78 }
79 // For the secure version, we track the buffer size. If we run out of
80 // buffer space, we still read in the rest of the current line until we
81 // reach '\n' or EOF, but we discard the characters and reset the buffer
82 // to be zero-filled.
83 else
84 {
86
87 Character* result_it = result;
88 while (c != '\n' && c != stdio_traits::eof)
89 {
90 if (available > 0)
91 {
92 --available;
93 *result_it++ = static_cast<Character>(c);
94 }
95
96 c = stdio_traits::getc_nolock(stdin);
97 }
98
99 // If we ran out of space, clear the buffer and return failure:
100 if (available == 0)
101 {
104 }
105
106 *result_it = '\0';
108 }
109 }
111 {
113 }
115
116 return return_value;
117}
#define EINVAL
Definition: acclib.h:90
#define _RETURN_BUFFER_TOO_SMALL_ERROR(_String, _Size, _Ret)
#define _FILL_STRING
#define _RESET_STRING(_String, _Size)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
static WCHAR available[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2336
const GLubyte * c
Definition: glext.h:8905
_CRTIMP void __cdecl _unlock_file(_Inout_ FILE *_File)
#define stdin
Definition: stdio.h:98
_CRTIMP void __cdecl _lock_file(_Inout_ FILE *_File)
#define c
Definition: ke_i.h:80
#define __try
Definition: pseh2_64.h:188
#define __leave
Definition: pseh2_64.h:192
#define __endtry
Definition: pseh2_64.h:191
#define __finally
Definition: pseh2_64.h:190

Variable Documentation

◆ result_size_in_characters

_In_ size_t const result_size_in_characters

Definition at line 35 of file gets.cpp.

Referenced by _getws_s(), gets_s(), and throw().