ReactOS 0.4.16-dev-2110-ge3521eb
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)
void CDECL perror(const char *str)
Definition: errno.c:337
int errno_t
Definition: corecrt.h:249
_ACRTIMP errno_t __cdecl wcstombs_s(size_t *, char *, size_t, const wchar_t *, size_t)
Definition: wcs.c:776
#define INT_MAX
Definition: limits.h:26
#define _TRUNCATE
Definition: stdlib.h:45
#define L(x)
Definition: resources.c:13