ReactOS 0.4.16-dev-959-g2ec3a19
_strerr.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_traits.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for _strerr.cpp:

Go to the source code of this file.

Functions

static char *&__cdecl get_strerror_buffer (__acrt_ptd *const ptd, char) throw ()
 
static wchar_t *&__cdecl get_strerror_buffer (__acrt_ptd *const ptd, wchar_t) throw ()
 
static errno_t __cdecl append_message (_Inout_updates_z_(buffer_count) char *const buffer, size_t const buffer_count, char const *const message) throw ()
 
static errno_t __cdecl append_message (_Inout_updates_z_(buffer_count) wchar_t *const buffer, size_t const buffer_count, char const *const message) throw ()
 
template<typename Character >
_Ret_z_ _Success_ (return !=0) static Character *__cdecl common_strerror(Character const *const message) throw ()
 
char *__cdecl _strerror (char const *const message)
 
wchar_t *__cdecl __wcserror (wchar_t const *const message)
 
template<typename Character >
static errno_t __cdecl common_strerror_s (_Out_writes_z_(buffer_count) Character *const buffer, size_t const buffer_count, Character const *const message) throw ()
 
errno_t __cdecl _strerror_s (char *const buffer, size_t const buffer_count, char const *const message)
 
errno_t __cdecl __wcserror_s (wchar_t *const buffer, size_t const buffer_count, wchar_t const *const message)
 

Variables

size_t const minimum_message_length = 5
 

Function Documentation

◆ __wcserror()

wchar_t *__cdecl __wcserror ( wchar_t const *const  message)

Definition at line 124 of file _strerr.cpp.

125{
126 return common_strerror(message);
127}
static _Ret_z_ Character *__cdecl common_strerror(int const error_number)
Definition: strerror.cpp:79
Definition: tftpd.h:60

◆ __wcserror_s()

errno_t __cdecl __wcserror_s ( wchar_t *const  buffer,
size_t const  buffer_count,
wchar_t const *const  message 
)

Definition at line 196 of file _strerr.cpp.

201{
203}
static errno_t __cdecl common_strerror_s(_Out_writes_z_(buffer_count) Character *const buffer, size_t const buffer_count, Character const *const message)
Definition: _strerr.cpp:157
GLuint buffer
Definition: glext.h:5915
size_t const buffer_count
Definition: xtoa.cpp:36

◆ _strerror()

char *__cdecl _strerror ( char const *const  message)

Definition at line 119 of file _strerr.cpp.

120{
121 return common_strerror(message);
122}

◆ _strerror_s()

errno_t __cdecl _strerror_s ( char *const  buffer,
size_t const  buffer_count,
char const *const  message 
)

Definition at line 187 of file _strerr.cpp.

192{
194}

◆ _Success_()

template<typename Character >
_Ret_z_ _Success_ ( return = 0) const
throw (
)

Definition at line 77 of file _strerr.cpp.

81{
82 using traits = __crt_char_traits<Character>;
83
84 errno_t const original_errno_value = errno;
85
87 if (!ptd)
88 return nullptr;
89
90 Character*& buffer = get_strerror_buffer(ptd, Character());
91 if (!buffer)
92 buffer = _calloc_crt_t(Character, strerror_buffer_count).detach();
93
94 if (!buffer)
95 return nullptr;
96
97 buffer[0] = '\0';
98
99 // CRT_REFACTOR TODO AppCRT/DesktopCRT Dependencies
100 // (We should be using mbs* functions here).
101 if (message && message[0] != '\0')
102 {
103 Character const colon[] = { ':', ' ', '\0' };
104
105 // Leave room for the ": \n\0"
106 _ERRCHECK(traits::tcsncat_s(buffer, strerror_buffer_count, message, strerror_buffer_count - 4));
107 _ERRCHECK(traits::tcscat_s(buffer, strerror_buffer_count, colon));
108 }
109
110 char const* const system_message = _get_sys_err_msg(original_errno_value);
111 _ERRCHECK(append_message(buffer, strerror_buffer_count, system_message));
112
113 Character const newline[] = { '\n', '\0' };
114 _ERRCHECK(traits::tcscat_s(buffer, strerror_buffer_count, newline));
115
116 return buffer;
117}
static errno_t __cdecl append_message(_Inout_updates_z_(buffer_count) char *const buffer, size_t const buffer_count, char const *const message)
Definition: _strerr.cpp:51
static char *&__cdecl get_strerror_buffer(__acrt_ptd *const ptd, char)
Definition: _strerr.cpp:41
_Ret_z_ __inline char const * _get_sys_err_msg(size_t const m)
#define _ERRCHECK(e)
__acrt_ptd *__cdecl __acrt_getptd_noexit(void)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
#define errno
Definition: errno.h:18
int errno_t
Definition: corecrt.h:615

◆ append_message() [1/2]

static errno_t __cdecl append_message ( _Inout_updates_z_(buffer_count) char *const  buffer,
size_t const  buffer_count,
char const *const  message 
)
throw (
)
static

Definition at line 51 of file _strerr.cpp.

56{
58}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_opt_ _Locale strncat_s
Definition: string.h:263

Referenced by _Success_().

◆ append_message() [2/2]

static errno_t __cdecl append_message ( _Inout_updates_z_(buffer_count) wchar_t *const  buffer,
size_t const  buffer_count,
char const *const  message 
)
throw (
)
static

Definition at line 60 of file _strerr.cpp.

65{
66 size_t const buffer_length = wcslen(buffer);
67 return mbstowcs_s(
68 nullptr,
69 buffer + buffer_length,
70 buffer_count - buffer_length,
71 message,
72 buffer_count - buffer_length - 2);
73}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
errno_t mbstowcs_s(size_t *cchConverted, wchar_t *widechar, size_t charoutct, const char *multibyte, size_t count)
Definition: mbstowcs.cpp:316

◆ common_strerror_s()

template<typename Character >
static errno_t __cdecl common_strerror_s ( _Out_writes_z_(buffer_count) Character *const  buffer,
size_t const  buffer_count,
Character const *const  message 
)
throw (
)
static

Definition at line 157 of file _strerr.cpp.

162{
163 using traits = __crt_char_traits<Character>;
164
165 errno_t const original_errno_value = errno;
166
169 buffer[0] = '\0';
170
171 if (message &&
172 message[0] != '\0' &&
173 traits::tcslen(message) < (buffer_count - 2 - minimum_message_length))
174 {
175 Character const colon[] = { ':', ' ', '\0' };
176 _ERRCHECK(traits::tcscpy_s(buffer, buffer_count, message));
177 _ERRCHECK(traits::tcscat_s(buffer, buffer_count, colon));
178 }
179
180 // Append the error message at the end of the buffer:
181 return traits::tcserror_s(
182 buffer + traits::tcslen(buffer),
183 buffer_count - traits::tcslen(buffer),
184 original_errno_value);
185}
size_t const minimum_message_length
Definition: _strerr.cpp:154
#define EINVAL
Definition: acclib.h:90
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)

Referenced by __wcserror_s(), and _strerror_s().

◆ get_strerror_buffer() [1/2]

static char *&__cdecl get_strerror_buffer ( __acrt_ptd *const  ptd,
char   
)
throw (
)
static

Definition at line 41 of file _strerr.cpp.

42{
43 return ptd->_strerror_buffer;
44}

Referenced by _Success_().

◆ get_strerror_buffer() [2/2]

static wchar_t *&__cdecl get_strerror_buffer ( __acrt_ptd *const  ptd,
wchar_t   
)
throw (
)
static

Definition at line 46 of file _strerr.cpp.

47{
48 return ptd->_wcserror_buffer;
49}

Variable Documentation

◆ minimum_message_length

size_t const minimum_message_length = 5

Definition at line 154 of file _strerr.cpp.

Referenced by common_strerror_s().