ReactOS 0.4.16-dev-927-g467dec4
wperror.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_lowio.h>
#include <io.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for wperror.cpp:

Go to the source code of this file.

Functions

void __cdecl _wperror (wchar_t const *const wide_user_prefix)
 

Function Documentation

◆ _wperror()

void __cdecl _wperror ( wchar_t const *const  wide_user_prefix)

Definition at line 38 of file wperror.cpp.

39{
40 // If the user did not provide a prefix, we can just call perror:
41 if (wide_user_prefix == nullptr || wide_user_prefix[0] == L'\0')
42 return perror(nullptr);
43
44 // Otherwise, we need to convert the prefix into a narrow string then pass
45 // it to perror:
46 size_t required_count = 0;
47 _ERRCHECK_EINVAL_ERANGE(wcstombs_s(&required_count, nullptr, 0, wide_user_prefix, INT_MAX));
48 if (required_count == 0)
49 return;
50
51 __crt_unique_heap_ptr<char> const narrow_user_prefix(_calloc_crt_t(char, required_count));
52 if (narrow_user_prefix.get() == nullptr)
53 return;
54
55 errno_t const conversion_result = _ERRCHECK_EINVAL_ERANGE(wcstombs_s(
56 nullptr,
57 narrow_user_prefix.get(),
58 required_count,
59 wide_user_prefix,
60 _TRUNCATE));
61
62 if (conversion_result != 0)
63 return;
64
65 return perror(narrow_user_prefix.get());
66}
#define _ERRCHECK_EINVAL_ERANGE(e)
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define INT_MAX
Definition: intsafe.h:150
_Check_return_wat_ _CRTIMP errno_t __cdecl wcstombs_s(_Out_opt_ size_t *pcchConverted, _Out_writes_bytes_to_opt_(cjDstSize, *pcchConverted) char *pmbsDst, _In_ size_t cjDstSize, _In_z_ const wchar_t *pwszSrc, _In_ size_t cjMaxCount)
#define L(x)
Definition: ntvdm.h:50
int errno_t
Definition: corecrt.h:615
#define _TRUNCATE
Definition: corecrt.h:278