ReactOS 0.4.16-dev-736-g28b802b
wcstombs.cpp File Reference
#include <corecrt_internal_mbstring.h>
#include <corecrt_internal_ptd_propagation.h>
#include <corecrt_internal_securecrt.h>
#include <ctype.h>
#include <errno.h>
#include <locale.h>
#include <stdint.h>
#include <stdlib.h>
Include dependency graph for wcstombs.cpp:

Go to the source code of this file.

Functions

 _Post_satisfies_ (return<=cnt &&return<=_String_length_(string+1)) static size_t __cdecl wcsncnt(_In_reads_or_z_(cnt) const wchar_t *string
 
 while (--n &&*cp) cp++
 
 if (n &&! *cp) return cp - string+1
 
 _Success_ (return !=static_cast< size_t >(-1)) static size_t __cdecl _wcstombs_l_helper(_Out_writes_(n) char *s
 
 if (s &&n==0) return 0
 
 _UCRT_VALIDATE_RETURN (ptd, pwcs !=nullptr, EINVAL,(size_t) -1)
 
 if (locale->locinfo->_public._locale_lc_codepage==CP_UTF8)
 
 if (s)
 

Variables

_In_ size_t cnt
 
wchar_tcp = (wchar_t *)string
 
_In_z_ const wchar_tpwcs
 
_In_z_ const wchar_t _In_ size_t n
 
_In_z_ const wchar_t _In_ size_t _Inout_ __crt_cached_ptd_host & ptd
 
int i
 
int retval
 
char buffer [MB_LEN_MAX]
 
BOOL defused = 0
 
const _locale_t locale = ptd.get_locale()
 

Function Documentation

◆ _Post_satisfies_()

_Post_satisfies_ ( return<=cnt &&return<=  _String_length_string+1) const

◆ _Success_()

_Success_ ( return = static_cast<size_t>(-1))

Definition at line 1028 of file fsctrl.c.

3189{
3191
3192 PVPB Vpb = Vcb->Vpb;
3193 PVPB OldVpb;
3194
3195 BOOLEAN Remount = FALSE;
3196
3197 PAGED_CODE();
3198
3199 UNREFERENCED_PARAMETER( IrpContext );
3200
3201 //
3202 // Check whether we are looking for a device only Mvcb.
3203 //
3204
3205 for (Link = CdData.VcbQueue.Flink;
3206 Link != &CdData.VcbQueue;
3207 Link = Link->Flink) {
3208
3209 *OldVcb = CONTAINING_RECORD( Link, VCB, VcbLinks );
3210
3211 //
3212 // Skip ourselves.
3213 //
3214
3215 if (Vcb == *OldVcb) { continue; }
3216
3217 //
3218 // Look at the Vpb and state of the previous Vcb.
3219 //
3220
3221 OldVpb = (*OldVcb)->Vpb;
3222
3223 if ((OldVpb != Vpb) &&
3224 (OldVpb->RealDevice == Vpb->RealDevice) &&
3225 ((*OldVcb)->VcbCondition == VcbNotMounted)) {
3226
3227 //
3228 // If the current disk is a raw disk then it can match a previous music or
3229 // raw disk.
3230 //
3231
3232 if (FlagOn( Vcb->VcbState, VCB_STATE_AUDIO_DISK)) {
3233
3234 if (FlagOn( (*OldVcb)->VcbState, VCB_STATE_AUDIO_DISK )) {
3235
3236 //
3237 // If we have both TOC then fail the remount if the lengths
3238 // are different or they don't match.
3239 //
3240
3241 if ((Vcb->TocLength != (*OldVcb)->TocLength) ||
3242 ((Vcb->TocLength != 0) &&
3243 !RtlEqualMemory( Vcb->CdromToc,
3244 (*OldVcb)->CdromToc,
3245 Vcb->TocLength ))) {
3246
3247 continue;
3248 }
3249
3250 Remount = TRUE;
3251 break;
3252 }
3253
3254 //
3255 // The current disk is not a raw disk. Go ahead and compare
3256 // serial numbers, volume label and TOC.
3257 //
3258
3259 }
3260 else if ((OldVpb->SerialNumber == Vpb->SerialNumber) &&
3261 (Vcb->TocLength == (*OldVcb)->TocLength) &&
3262 ((Vcb->TocLength == 0) || RtlEqualMemory( Vcb->CdromToc,
3263 (*OldVcb)->CdromToc,
3264 Vcb->TocLength )) &&
3265 (Vpb->VolumeLabelLength == OldVpb->VolumeLabelLength) &&
3266 (RtlEqualMemory( OldVpb->VolumeLabel,
3267 Vpb->VolumeLabel,
3268 Vpb->VolumeLabelLength ))) {
3269 //
3270 // Remember the old Vcb. Then set the return value to
3271 // TRUE and break.
3272 //
3273
3274 Remount = TRUE;
3275 break;
3276 }
3277 }
3278 }
3279
3280 return Remount;
3281}
#define PAGED_CODE()
unsigned char BOOLEAN
CD_DATA CdData
Definition: cddata.c:42
#define VCB_STATE_AUDIO_DISK
Definition: cdstruc.h:712
@ VcbNotMounted
Definition: cdstruc.h:490
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1676
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define Vcb
Definition: cdprocs.h:1415
LIST_ENTRY VcbQueue
Definition: cdstruc.h:334
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: cdstruc.h:498
Definition: iotypes.h:189
WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH/sizeof(WCHAR)]
Definition: iotypes.h:198
USHORT VolumeLabelLength
Definition: iotypes.h:193
ULONG SerialNumber
Definition: iotypes.h:196
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:195
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static int Link(const char **args)
Definition: vfdcmd.c:2414

◆ _UCRT_VALIDATE_RETURN()

_UCRT_VALIDATE_RETURN ( ptd  ,
pwcs = nullptr,
EINVAL  ,
(size_t) -  1 
)

◆ if() [1/4]

if ( locale->locinfo->_public.  _locale_lc_codepage = CP_UTF8)

Definition at line 106 of file wcstombs.cpp.

107 {
110 }
static int state
Definition: maze.c:121
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
size_t __cdecl __wcsrtombs_utf8(char *dst, const wchar_t **src, size_t len, mbstate_t *ps, __crt_cached_ptd_host &ptd)
Definition: wcrtomb.cpp:439
_In_z_ const wchar_t _In_ size_t _Inout_ __crt_cached_ptd_host & ptd
Definition: wcstombs.cpp:89
_In_z_ const wchar_t * pwcs
Definition: wcstombs.cpp:85

◆ if() [2/4]

if ( n &&! *  cp)

◆ if() [3/4]

if ( s &&  n = =0)

◆ if() [4/4]

if ( s  )

Definition at line 112 of file wcstombs.cpp.

113 {
114 if ( locale->locinfo->locale_name[LC_CTYPE] == nullptr )
115 {
116 /* C locale: easy and fast */
117 /* Actually, there are such wchar_t characters which are > 255,
118 * but they can be transformed to a valid single byte char
119 * (i.e. a char in the C locale case). Like, for example,
120 * alternative digits in unicode like Arabic-Indic U+0660..U+0669.
121 * The problem is that WideCharToMultiByte() does not translate those
122 * wchar_t unless we pass the correct codepage (1256, Arabic).
123 * See bug VSW:192653.
124 */
125 while(count < n)
126 {
127 if (static_cast<uint16_t>(*pwcs) > 0xFF) /* validate high byte */
128 {
129 ptd.get_errno().set(EILSEQ);
130 return (size_t)-1; /* error */
131 }
132 s[count] = (char) *pwcs;
133 if (*pwcs++ == L'\0')
134 {
135 return count;
136 }
137 count++;
138 }
139 return count;
140 }
141 else
142 {
143
144 if (1 == locale->locinfo->_public._locale_mb_cur_max)
145 {
146 /* If SBCS, one wchar_t maps to one char */
147
148 /* WideCharToMultiByte will compare past nullptr - reset n */
149 if (n > 0)
150 {
151 n = wcsncnt(pwcs, n);
152 }
153 if ( ((count = __acrt_WideCharToMultiByte( locale->locinfo->_public._locale_lc_codepage,
154 0,
155 pwcs,
156 (int)n,
157 s,
158 (int)n,
159 nullptr,
160 &defused )) != 0) &&
161 (!defused) )
162 {
163 if (s[count - 1] == '\0')
164 {
165 count--; /* don't count NUL */
166 }
167
168 return count;
169 }
170
171 ptd.get_errno().set(EILSEQ);
172 return (size_t)-1;
173 }
174 else
175 {
176
177 /* If MBCS, wchar_t to char mapping unknown */
178
179 /* Assume that usually the buffer is large enough */
180 if ( ((count = __acrt_WideCharToMultiByte( locale->locinfo->_public._locale_lc_codepage,
181 0,
182 pwcs,
183 -1,
184 s,
185 (int)n,
186 nullptr,
187 &defused )) != 0) &&
188 (!defused) )
189 {
190 return count - 1; /* don't count NUL */
191 }
192
194 {
195 ptd.get_errno().set(EILSEQ);
196 return (size_t)-1;
197 }
198
199 /* buffer not large enough, must do char by char */
200 while (count < n)
201 {
202 int mb_cur_max = locale->locinfo->_public._locale_mb_cur_max;
203 if ( ((retval = __acrt_WideCharToMultiByte( locale->locinfo->_public._locale_lc_codepage,
204 0,
205 pwcs,
206 1,
207 buffer,
208 __min(MB_LEN_MAX, mb_cur_max),
209 nullptr,
210 &defused )) == 0)
211 || defused )
212 {
213 ptd.get_errno().set(EILSEQ);
214 return (size_t)-1;
215 }
216
217 /* enforce this for prefast */
218 if (retval < 0 ||
220 {
221 ptd.get_errno().set(EILSEQ);
222 return (size_t)-1;
223 }
224
225 if (count + retval > n)
226 return count;
227
228 for (i = 0; i < retval; i++, count++) /* store character */
229 {
230 if((s[count] = buffer[i])=='\0')
231 {
232 return count;
233 }
234 }
235
236 pwcs++;
237 }
238
239 return count;
240 }
241 }
242 }
return __acrt_WideCharToMultiByte(code_page, 0, buffer.get(), -1, result_size !=0 ? result :nullptr, result_size, nullptr, nullptr)
unsigned short int uint16_t
Definition: acefiex.h:54
Definition: _locale.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
unsigned char
Definition: typeof.h:29
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
#define LC_CTYPE
Definition: locale.h:19
#define __min(a, b)
Definition: stdlib.h:102
#define MB_LEN_MAX
Definition: stdlib.h:19
#define L(x)
Definition: ntvdm.h:50
#define EILSEQ
Definition: errno.h:109
#define _countof(array)
Definition: sndvol32.h:70
int retval
Definition: wcstombs.cpp:91
BOOL defused
Definition: wcstombs.cpp:93
int i
Definition: wcstombs.cpp:91
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ while()

while ( --n &&*  cp)

Variable Documentation

◆ buffer

Definition at line 92 of file wcstombs.cpp.

◆ cnt

return cnt
Initial value:
{
size_t n = cnt+1
_In_ size_t cnt
Definition: wcstombs.cpp:43

Definition at line 41 of file wcstombs.cpp.

Referenced by _check_process_enum(), _ItemizeInternal(), _mbsnbcat(), _mbsnbcat_l(), _mbsnbcpy(), _mbsnbcpy_l(), _mbsncat(), _mbsncat_l(), _mbsnccnt(), _mbsncpy(), _mbsncpy_l(), _snprintf(), _test_range_move(), _test_range_moveend(), _test_range_movestart(), _vsnprintf(), StartMenu::AddShellEntries(), alloc_handler_vector(), BSCInternetBindInfo_GetBindString(), Pane::calc_single_width(), Pane::calc_widths(), ChildWndProc(), collection_GetTypeInfoCount(), compat_fopen(), condvar_consumer(), convert_params(), XMLStorage::XMLNode::count(), CountUniqueItems_Aux(), debugstr_flags(), dump_shell_namespace(), dwarf2_parse_array_type(), EnumConnections_Next(), enumeration_callback(), EnumFORMATETC_Next(), ShellDirectory::extract_icons(), file_cvt(), filewrite(), fillbytes(), XMLStorage::XMLNode::filter(), fix_filename_for_c(), FreeTestCmdStrings(), FT_Raccess_Get_DataOffsets(), Function_apply(), Function_call(), handle_address_cmd(), handle_escape_cmd(), HTTP_HttpSendRequestW(), icy_fullread(), inet_ntop(), ShellBrowser::InsertSubitems(), invoketest_GetTypeInfoCount(), XMLStorage::XMLPos::iterate(), XMLStorage::const_XMLPos::iterate(), js_snprintf(), LineDDA(), LISTVIEW_KeyDown(), main(), match_mod(), MCI_SysInfo(), mem_cmp(), mem_cpy(), mem_set(), MIDI_mciFindNextEvent(), move_by_chars(), move_by_words(), movebytes(), MSACM_RegisterAllDrivers(), msvcrt_flush_buffer(), MyDrawText(), mymemchr(), MainFrameBase::OpenShellFolders(), otv_MathItalicsCorrectionInfo_validate(), otv_MathKern_validate(), otv_MathKernInfo_validate(), plain_fullread(), DesktopShellView::PositionIcons(), ShellDirectory::read_directory(), reader_parse_externalid(), CControlPanelEnum::RegisterRegistryCPanelApps(), ResizeTabChild(), SetupDiGetDriverInfoDetailA(), SHPackDispParams(), SHPackDispParamsV(), skip_input_bytes(), srwlock_example_thread(), test_acquire(), test_GetKeyboardLayoutList(), test_object_info(), test_ScriptGetCMap(), test_SQLInstallDriverEx(), test_SQLInstallTranslatorEx(), test_startSession(), translate_line(), write_vc(), xdr_opaque(), xsltNumberFormatGetAnyLevel(), xsltNumberFormatGetMultipleLevel(), and zerobytes().

◆ cp

Definition at line 45 of file wcstombs.cpp.

◆ defused

BOOL defused = 0

Definition at line 93 of file wcstombs.cpp.

Referenced by if().

◆ i

int i

Definition at line 91 of file wcstombs.cpp.

Referenced by if().

◆ locale

Definition at line 104 of file wcstombs.cpp.

◆ n

Definition at line 86 of file wcstombs.cpp.

◆ ptd

_In_z_ const wchar_t _In_ size_t _Inout_ __crt_cached_ptd_host& ptd
Initial value:
{
size_t count = 0

Definition at line 87 of file wcstombs.cpp.

Referenced by if().

◆ pwcs

◆ retval

int retval

Definition at line 91 of file wcstombs.cpp.

Referenced by $relaytrace$StdcallFunction(), $relaytrace$Stdcalli386x64(), $relaytrace$StdcallVersionRange(), __crt_mbstring::__c16rtomb_utf8(), __emul(), __emulu(), __fp_unordered_compare(), __ll_lshift(), __ll_rshift(), __crt_mbstring::__mbrtoc16_utf8(), __rdtsc(), __readeflags(), __readmsr(), __readpmc(), __segmentlimit(), __ull_rshift(), __crt_mbstring::__wcsrtombs_utf8(), _bittest(), _bittestandcomplement(), _bittestandreset(), _bittestandset(), _byteswap_uint64(), _byteswap_ulong(), _byteswap_ushort(), _cgetws_s(), _clearfp(), _configthreadlocale(), _cputs(), _cwprintf(), _endthreadex(), _fgets(), _handle_error(), _handle_errorf(), _heapset(), _hypot(), _hypotf(), _interlockedbittestandreset(), _interlockedbittestandset(), _InterlockedCompareExchange(), _InterlockedCompareExchange16(), _InterlockedCompareExchange64(), _InterlockedCompareExchange8(), _InterlockedCompareExchangePointer(), _InterlockedExchange(), _InterlockedExchange16(), _InterlockedExchange8(), _InterlockedExchangeAdd(), _InterlockedExchangeAdd16(), _InterlockedExchangeAdd8(), _InterlockedExchangePointer(), _invoke_matherr(), _isindst(), _lrotl(), _lrotr(), _mbsicmp_l(), _mbslwr_s_l(), _mbsspn_l(), _mbsupr_s_l(), _onexit(), _rotl(), _rotl16(), _rotl8(), _rotr(), _rotr16(), _rotr8(), _strxfrm_l(), _Success_(), _tfullpath(), _VCrtDbgReportA(), _VCrtDbgReportW(), _WLocale_mbtowc(), _wsetlocale(), _wsetlocale_nolock(), _y0(), _y1(), _yn(), ata_bblk(), automatic_updates_get_ServiceEnabled(), automatic_updates_get_Settings(), anonymous_namespace{mbrtoc16.cpp}::begin_surrogate_state(), cmd_path(), cmd_prompt(), cmd_set(), COMDLG32_FindReplaceDlgProc(), CommandAssoc(), control_service(), create_bad_block_inode(), create_channelbsc(), create_file(), create_fileW(), create_journal_dev(), create_key(), create_lost_and_found(), create_root_dir(), DATETIME_SetFormatA(), delete_file(), delete_fileW(), DevInstallW(), DIALOG_DoDialogBox(), do_error_dialog(), do_ndr_client_call(), DoTelnetHandshake(), draw_diag_edge(), draw_rect_edge(), EndDialog(), enum_key(), enum_values(), event_do_dialog(), execute_from_key(), ext2_alloc_block(), ext2_allocate_group_table(), ext2_allocate_tables(), ext2_flush(), ext2_mkdir(), ext2_read_block(), ext2_write_bitmaps(), ext2_write_block(), ext2_write_block_bitmap(), ext2_write_inode_bitmap(), ext3_add_entry(), externalui_message_callback(), externalui_message_string_callback(), externalui_record_callback(), FILEDLG95_HandleCustomDialogMessages(), FILEDLG95_SendFileOK(), fill_file_description(), FindExecutableA(), FindExecutableW(), SEALED_::FireAutoReconnecting(), SEALED_::FireConfirmClose(), SEALED_::FireEventInsideApartment(), SEALED_::FireEventOutsideApartment(), SEALED_::FireReceivedTSPublicKey(), FTPFILE_QueryDataAvailable(), full_file_path_name_in_a_CWD(), GDI32_GdipDrawPath(), GDI32_GdipFillPath(), GdipCreateBitmapFromHBITMAP(), GdipCreateFromHDC2(), GdipCreateMetafileFromWmf(), GdipDrawLinesI(), GdipDrawPath(), gen_proxy(), get_func_oi2_flags(), get_owner(), get_stringvalue(), GetAcceptLanguagesA(), getbyte(), GetClassInfoA(), GetClassInfoW(), GetFileVersionInfoExA(), GetFileVersionInfoSizeExA(), getopt(), getopt_long(), CQueryAssociations::GetString(), GetWin32Version(), graphics_from_image(), HandleUninstallCommand(), if(), InstallDevInstEx(), IntDispatchMessage(), IntDrawDiagEdge(), IntDrawRectEdge(), IntDrawState(), IntSyscall(), SEALED_::InvokeSinks(), is_old_shell32(), ITypeInfo_fnInvoke(), journal_init_journal_head_cache(), ldap_start_tls_sA(), ldap_start_tls_sW(), llrint(), llrintf(), llrintl(), LoadStringA(), lrint(), lrintf(), lrintl(), Main_DirectDraw_SetDisplayMode2(), MakeArgv(), FxObject::MarkDeleteCalledLocked(), NdrStubCall2(), NmiClearFlag(), NtGdiExtSelectClipRgn(), open_driver_reg(), operator_new(), pagesetup_change_printer(), pagesetup_update_papersize(), PAINTING_DrawStateJam(), PDEVOBJ_bSwitchMode(), process_get_owner(), QueryInfoHKCRKey(), read_bitmaps(), ReceiveLine(), reg_create_key(), reg_enum_key(), reg_enum_values(), reg_get_stringvalue(), RegTGetDwordValue(), RegTGetStringValue(), __crt_mbstring::reset_and_return(), rint(), rintf(), rintl(), round_mantissa(), RtlTimeToTimeFields(), run_script(), SCardAddReaderToGroupA(), SearchDriverRecursive(), security_get_sd(), security_set_sd(), SendDriverMessage(), FxIrp::SendIrpSynchronously(), sendmail_extended_mapi(), service_pause_service(), service_resume_service(), service_start_service(), service_stop_service(), shader_arb_generate_pshader(), SHELL_execute(), SHELL_execute_url(), SHELL_ExecuteW(), SHELL_FindExecutable(), SHELL_quote_and_execute(), shellex_get_contextmenu(), SHFormatDateTimeA(), SHGetRestriction(), snprintfW(), sprintfW(), start_service(), StopWatchA(), systeminfo_get_RebootRequired(), t1_ps_get_font_value(), telCommandLine(), Test82(), test_CallNtPowerInformation(), test_CanUserWritePwrScheme(), test_copy(), test_DeletePwrScheme(), test_EnumPwrSchemes(), test_externalui(), test_externalui_message(), test_get_inf_class(), test_GetDefaultPrinter(), test_GetDlgItem(), test_GetMouseMovePointsEx(), test_GetPwrDiskSpindownRange(), test_GetSetActivePwrScheme(), test_info(), test_info_size(), test_InternetQueryOptionA(), test_LZOpenFileA(), test_LZOpenFileW(), test_move(), test_OpenFile(), test_ReadPwrScheme(), test_rename(), test_retval(), test_RpcExceptionFilter(), test_sequence(), test_SetWindowLong(), test_StdRegProv(), test_StringTableAddString(), test_StringTableAddStringEx(), test_StringTableLookUpString(), test_StringTableLookUpStringEx(), test_SystemSecurity(), test_Win32_Process(), test_Win32_Service(), test_WritePwrScheme(), test_wshshell(), TIME_CompTimeZoneID(), TREEVIEW_GetNextItem(), UDFDissectName(), UDFGetOptUlongInherited(), UDFPhysLbaToPart(), update_session_CreateUpdateDownloader(), update_session_CreateUpdateInstaller(), update_session_CreateUpdateSearcher(), VerFindFileA(), VerFindFileW(), warning(), Widget_Value(), write_func_param_struct(), write_function_stub(), write_inode_tables(), write_procformatstring_func(), and zero_blocks().