int __cdecl vswprintf_s ( wchar_t *string, size_t sizeInWords, const wchar_t *format, va_list ap ) { int retvalue = -1; /* validation section */ _VALIDATE_RETURN(format != NULL, EINVAL, -1); _VALIDATE_RETURN(string != NULL && sizeInWords > 0, EINVAL, -1); retvalue = _vswprintf_helper(_woutput_s, string, sizeInWords, format, ap); if (retvalue < 0) { string[0] = 0; _SECURECRT__FILL_STRING(string, sizeInWords, 1); } if (retvalue == -2) { _VALIDATE_RETURN(("Buffer too small" && 0), ERANGE, -1); } if (retvalue >= 0) { _SECURECRT__FILL_STRING(string, sizeInWords, retvalue + 1); } return retvalue; }
extern "C" int __cdecl _strnicmp_l( const char* dst, const char* src, size_t count, _locale_t plocinfo ) { int f, l; if (count) { _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(dst != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(src != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(count <= INT_MAX, EINVAL, _NLSCMPERROR); if (__LC_HANDLE(_loc_update.GetLocaleT()->locinfo)[LC_CTYPE] == _CLOCALEHANDLE) { return __ascii_strnicmp(dst, src, count); } else { do { f = _tolower_l((unsigned char)(*(dst++)), _loc_update.GetLocaleT()); l = _tolower_l((unsigned char)(*(src++)), _loc_update.GetLocaleT()); } while (--count && f && (f == l)); } return (f - l); } return (0); }
extern "C" int __cdecl _memicmp_l ( const void * first, const void * last, size_t count, _locale_t plocinfo ) { int f = 0, l = 0; const char *dst = (const char *)first, *src = (const char *)last; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(first != NULL || count == 0, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(last != NULL || count == 0, EINVAL, _NLSCMPERROR); if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_CTYPE] == NULL ) { return __ascii_memicmp(first, last, count); } else { while (count-- && f==l) { f = _tolower_l( (unsigned char)(*(dst++)), _loc_update.GetLocaleT() ); l = _tolower_l( (unsigned char)(*(src++)), _loc_update.GetLocaleT() ); } } return ( f - l ); }
int __cdecl _setmode( int fh, int mode ) { int retval; _VALIDATE_RETURN(((mode == _O_TEXT) || (mode == _O_BINARY) || (mode == _O_WTEXT) || (mode == _O_U8TEXT) || (mode == _O_U16TEXT)), EINVAL, -1); _CHECK_FH_RETURN(fh, EBADF, -1); _VALIDATE_RETURN((fh >= 0 && (unsigned)fh < (unsigned)_nhandle), EBADF, -1); _VALIDATE_RETURN((_osfile(fh) & FOPEN), EBADF, -1); /* lock the file */ _lock_fh(fh); __try { if (_osfile(fh) & FOPEN) /* set the text/binary mode */ { retval = _setmode_nolock(fh, mode); } else { errno = EBADF; _ASSERTE(("Invalid file descriptor. File possibly closed by a different thread", 0)); retval = -1; } } __finally { /* unlock the file */ _unlock_fh(fh); } /* Return to user (_setmode_nolock sets errno, if needed) */ return (retval); }
void* __fileDECL bsearch( void const* const key, void const* const base, size_t num, size_t const width, int (__fileDECL* const compare)(void const*, void const*) ) #endif // __USE_CONTEXT { _VALIDATE_RETURN(base != nullptr || num == 0, EINVAL, nullptr); _VALIDATE_RETURN(width > 0, EINVAL, nullptr); _VALIDATE_RETURN(compare != nullptr, EINVAL, nullptr); char const* lo = reinterpret_cast<char const*>(base); char const* hi = reinterpret_cast<char const*>(base) + (num - 1) * width; // Reentrancy diligence: Save (and unset) global-state mode to the stack before making callout to 'compare' __crt_state_management::scoped_global_state_reset saved_state; // We allow a nullptr key here because it breaks some older code and because // we do not dereference this ourselves so we can't be sure that it's a // problem for the comparison function while (lo <= hi) { size_t const half = num / 2; if (half != 0) { char const* const mid = lo + (num & 1 ? half : (half - 1)) * width; int const result = __COMPARE(context, key, mid); if (result == 0) { return const_cast<void*>(static_cast<void const*>(mid)); } else if (result < 0) { hi = mid - width; num = num & 1 ? half : half - 1; } else { lo = mid + width; num = half; } } else if (num != 0) { return __COMPARE(context, key, lo) ? nullptr : const_cast<void*>(static_cast<void const*>(lo)); } else { break; } } return nullptr; }
extern "C" void* __cdecl _aligned_offset_malloc_base( size_t size, size_t align, size_t offset ) { uintptr_t ptr, retptr, gap; size_t nonuser_size,block_size; /* validation section */ _VALIDATE_RETURN(IS_2_POW_N(align), EINVAL, nullptr); _VALIDATE_RETURN(offset == 0 || offset < size, EINVAL, nullptr); align = (align > PTR_SZ ? align : PTR_SZ) -1; /* gap = number of bytes needed to round up offset to align with PTR_SZ*/ gap = (0 - offset)&(PTR_SZ -1); nonuser_size = PTR_SZ +gap +align; block_size = nonuser_size + size; _VALIDATE_RETURN_NOEXC(size <= block_size, ENOMEM, nullptr) if ( (ptr =(uintptr_t)malloc(block_size)) == (uintptr_t)nullptr) return nullptr; retptr =((ptr +nonuser_size+offset)&~align)- offset; ((uintptr_t *)(retptr - gap))[-1] = ptr; return (void *)retptr; }
int __cdecl fputws ( const wchar_t *string, FILE *stream ) { size_t length; int retval = 0; _VALIDATE_RETURN((string != NULL), EINVAL, WEOF); _VALIDATE_RETURN((stream != NULL), EINVAL, WEOF); length = wcslen(string); _lock_str(stream); __try { while (length--) { if (_putwc_nolock(*string++, stream) == WEOF) { retval = -1; break; } } } __finally { _unlock_str(stream); } return(retval); }
int __cdecl vfwprintf_helper ( WOUTPUTFN woutfn, FILE *str, const wchar_t *format, _locale_t plocinfo, va_list ap ) /* * 'V'ariable argument 'F'ile (stream) 'W'char_t 'PRINT', 'F'ormatted */ { REG1 FILE *stream; REG2 int buffing; REG3 int retval; _VALIDATE_RETURN( (str != NULL), EINVAL, -1); _VALIDATE_RETURN( (format != NULL), EINVAL, -1); /* Init stream pointer */ stream = str; _lock_str(stream); __try { buffing = _stbuf(stream); retval = woutfn(stream,format,plocinfo,ap ); _ftbuf(buffing, stream); } __finally { _unlock_str(stream); } return(retval); }
extern "C" int __cdecl _mbscoll_l( const unsigned char *s1, const unsigned char *s2, _locale_t plocinfo ) { int ret; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(s1 != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(s2 != NULL, EINVAL, _NLSCMPERROR); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return _strcoll_l((const char *)s1, (const char *)s2, plocinfo); if (0 == (ret = __crtCompareStringA( _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->mbcinfo->mblcid, SORT_STRINGSORT, (LPCSTR)s1, -1, (LPSTR)s2, -1, _loc_update.GetLocaleT()->mbcinfo->mbcodepage ))) { errno = EINVAL; return _NLSCMPERROR; } return ret - 2; }
extern "C" int __cdecl _mbsnbicoll_l( const unsigned char* s1, const unsigned char* s2, size_t n, _locale_t plocinfo ) { int ret; _LocaleUpdate _loc_update(plocinfo); if (n == 0) { return 0; } /* validation section */ _VALIDATE_RETURN(s1 != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(s2 != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(n <= INT_MAX, EINVAL, _NLSCMPERROR); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) { return _strnicoll_l((const char*)s1, (const char*)s2, n, plocinfo); } if (0 == (ret = __crtCompareStringA(_loc_update.GetLocaleT(), _loc_update.GetLocaleT()->mbcinfo->mblcid, SORT_STRINGSORT | NORM_IGNORECASE, (const char*)s1, (int)n, (char*)s2, (int)n, _loc_update.GetLocaleT()->mbcinfo->mbcodepage))) { return _NLSCMPERROR; } return ret - 2; }
static int __cdecl vscan_fn ( INPUTFN inputfn, const char *string, const char *format, va_list arglist ) { miniFILE str; miniFILE *infile = &str; int retval; size_t count = strlen(string); _VALIDATE_RETURN( (string != NULL), EINVAL, EOF); _VALIDATE_RETURN( (format != NULL), EINVAL, EOF); infile->_flag = _IOREAD|_IOSTRG|_IOMYBUF; infile->_ptr = infile->_base = (char *) string; if(count>(INT_MAX/sizeof(char))) { /* old-style functions allow any large value to mean unbounded */ infile->_cnt = INT_MAX; } else { infile->_cnt = (int)count*sizeof(char); } retval = (inputfn(infile, ( const unsigned char* )format, arglist)); return(retval); }
extern "C" int __cdecl _stricoll_l ( const char *_string1, const char *_string2, _locale_t plocinfo ) { int ret; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR); if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr ) { return _stricmp(_string1, _string2); } if ( 0 == (ret = __acrt_CompareStringA(_loc_update.GetLocaleT(), _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE], SORT_STRINGSORT | NORM_IGNORECASE, _string1, -1, _string2, -1, _loc_update.GetLocaleT()->locinfo->lc_collate_cp)) ) { errno = EINVAL; return _NLSCMPERROR; } return (ret - 2); }
/*** *char *_lfind(key, base, num, width, compare) - do a linear search * *Purpose: * Performs a linear search on the array, looking for the value key * in an array of num elements of width bytes in size. Returns * a pointer to the array value if found, NULL if not found. * *Entry: * char *key - key to search for * char *base - base of array to search * unsigned *num - number of elements in array * int width - number of bytes in each array element * int (*compare)() - pointer to function that compares two * array values, returning 0 if they are equal and non-0 * if they are different. Two pointers to array elements * are passed to this function. * *Exit: * if key found: * returns pointer to array element * if key not found: * returns NULL * *Exceptions: * Input parameters are validated. Refer to the validation section of the function. * *******************************************************************************/ #ifdef __USE_CONTEXT #define __COMPARE(context, p1, p2) (*compare)(context, p1, p2) #else /* __USE_CONTEXT */ #define __COMPARE(context, p1, p2) (*compare)(p1, p2) #endif /* __USE_CONTEXT */ #if !defined (_M_CEE) _CRTIMP #endif /* !defined (_M_CEE) */ #ifdef __USE_CONTEXT void *__fileDECL _lfind_s ( REG2 const void *key, REG1 const void *base, REG3 unsigned int *num, size_t width, int (__fileDECL *compare)(void *, const void *, const void *), void *context ) #else /* __USE_CONTEXT */ void *__fileDECL _lfind ( REG2 const void *key, REG1 const void *base, REG3 unsigned int *num, unsigned int width, int (__fileDECL *compare)(const void *, const void *) ) #endif /* __USE_CONTEXT */ { unsigned int place = 0; /* validation section */ _VALIDATE_RETURN(key != NULL, EINVAL, NULL); _VALIDATE_RETURN(num != NULL, EINVAL, NULL); _VALIDATE_RETURN(base != NULL || *num == 0, EINVAL, NULL); _VALIDATE_RETURN(width > 0, EINVAL, NULL); _VALIDATE_RETURN(compare != NULL, EINVAL, NULL); while (place < *num) { if (__COMPARE(context, key, base) == 0) { return (void *)base; } else { base = (char*)base + width; place++; } } return NULL; }
extern "C" int __cdecl _wcsicoll ( const wchar_t *_string1, const wchar_t *_string2 ) { if (!__acrt_locale_changed()) { wchar_t f,l; /* validation section */ _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR ); _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR ); do { f = __ascii_towlower(*_string1); l = __ascii_towlower(*_string2); _string1++; _string2++; } while ( (f) && (f == l) ); return (int)(f - l); } else { return _wcsicoll_l(_string1, _string2, nullptr); } }
extern "C" size_t __cdecl _strxfrm_l ( char *_string1, const char *_string2, size_t _count, _locale_t plocinfo ) { int dstlen; size_t retval = INT_MAX; /* NON-ANSI: default if OM or API error */ _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(_count <= INT_MAX, EINVAL, INT_MAX); _VALIDATE_RETURN(_string1 != NULL || _count == 0, EINVAL, INT_MAX); _VALIDATE_RETURN(_string2 != NULL, EINVAL, INT_MAX); /* pre-init output in case of error */ if(_string1!=NULL && _count>0) { *_string1='\0'; } if ( (_loc_update.GetLocaleT()->locinfo->lc_handle[LC_COLLATE] == _CLOCALEHANDLE) && (_loc_update.GetLocaleT()->locinfo->lc_collate_cp == _CLOCALECP) ) { _BEGIN_SECURE_CRT_DEPRECATION_DISABLE strncpy(_string1, _string2, _count); _END_SECURE_CRT_DEPRECATION_DISABLE return strlen(_string2); }
int __cdecl vfwscanf ( WINPUTFN winputfn, FILE *stream, const wchar_t *format, _locale_t plocinfo, va_list arglist ) /* * 'F'ile (stream) 'W'char_t 'SCAN', 'F'ormatted */ { int retval; _VALIDATE_RETURN((stream != NULL), EINVAL, EOF); _VALIDATE_RETURN((format != NULL), EINVAL, EOF); _lock_str(stream); __try { retval = (winputfn(stream, format, plocinfo, arglist)); } __finally { _unlock_str(stream); } return(retval); }
extern "C" int __cdecl _ismbslead_l( const unsigned char *string, const unsigned char *current, _locale_t plocinfo ) { /* validation section */ _VALIDATE_RETURN(string != NULL, EINVAL, 0); _VALIDATE_RETURN(current != NULL, EINVAL, 0); _LocaleUpdate _loc_update(plocinfo); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return 0; while (string <= current && *string) { if ( _ismbblead_l((*string), _loc_update.GetLocaleT()) ) { if (string++ == current) /* check lead byte */ return -1; if (!(*string)) return 0; } ++string; } return 0; }
extern "C" int __cdecl _ismbstrail_l( unsigned char const* string, unsigned char const* current, _locale_t const locale ) { _VALIDATE_RETURN(string != nullptr, EINVAL, 0); _VALIDATE_RETURN(current != nullptr, EINVAL, 0); _LocaleUpdate locale_update(locale); if (locale_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return 0; while (string <= current && *string) { if (_ismbblead_l((*string), locale_update.GetLocaleT())) { if (++string == current) // check trail byte return -1; if (*string == 0) return 0; } ++string; } return 0; }
extern "C" int __cdecl _strcoll_l ( const char *_string1, const char *_string2, _locale_t plocinfo ) { int ret; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(_string1 != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(_string2 != NULL, EINVAL, _NLSCMPERROR); if ( _loc_update.GetLocaleT()->locinfo->lc_handle[LC_COLLATE] == _CLOCALEHANDLE ) return strcmp(_string1, _string2); if ( 0 == (ret = __crtCompareStringA( _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->locinfo->lc_handle[LC_COLLATE], SORT_STRINGSORT, _string1, -1, _string2, -1, _loc_update.GetLocaleT()->locinfo->lc_collate_cp )) ) { errno = EINVAL; return _NLSCMPERROR; } return (ret - 2); }
extern "C" int __cdecl _mbsnbcmp_l( const unsigned char *s1, const unsigned char *s2, size_t n, _locale_t plocinfo ) { unsigned short c1, c2; if (n==0) return(0); _LocaleUpdate _loc_update(plocinfo); if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return strncmp((const char *)s1, (const char *)s2, n); /* validation section */ _VALIDATE_RETURN(s1 != nullptr, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(s2 != nullptr, EINVAL, _NLSCMPERROR); while (n--) { c1 = *s1++; if ( _ismbblead_l(c1, _loc_update.GetLocaleT()) ) { if (n==0) { c1 = 0; /* 'naked' lead - end of string */ c2 = _ismbblead_l(*s2, _loc_update.GetLocaleT()) ? 0 : *s2; goto test; } c1 = ( (*s1 == '\0') ? 0 : ((c1<<8) | *s1++) ); } c2 = *s2++; if ( _ismbblead_l(c2, _loc_update.GetLocaleT()) ) { if (n==0) { c2 = 0; /* 'naked' lead - end of string */ goto test; } --n; c2 = ( (*s2 == '\0') ? 0 : ((c2<<8) | *s2++) ); } test: if (c1 != c2) return( (c1 > c2) ? 1 : -1); if (c1 == 0) return(0); } return(0); }
int __cdecl _snprintf_c( char* string, size_t count, const char* format, ... ) #endif /* _SWPRINTFS_ERROR_RETURN_FIX */ #endif /* _COUNT_ */ { FILE str; REG1 FILE* outfile = &str; va_list arglist; REG2 int retval; _VALIDATE_RETURN((format != NULL), EINVAL, -1); #ifdef _COUNT_ _VALIDATE_RETURN((count == 0) || (string != NULL), EINVAL, -1); #else /* _COUNT_ */ _VALIDATE_RETURN((string != NULL), EINVAL, -1); #endif /* _COUNT_ */ va_start(arglist, format); #ifndef _COUNT_ outfile->_cnt = MAXSTR; #else /* _COUNT_ */ if (count > INT_MAX) { /* old-style functions allow any large value to mean unbounded */ outfile->_cnt = INT_MAX; } else { outfile->_cnt = (int)(count); } #endif /* _COUNT_ */ outfile->_flag = _IOWRT | _IOSTRG; outfile->_ptr = outfile->_base = string; retval = _output_l(outfile, format, NULL, arglist); if (string == NULL) { return (retval); } #ifndef _SWPRINTFS_ERROR_RETURN_FIX _putc_nolock('\0', outfile); /* no-lock version */ return (retval); #else /* _SWPRINTFS_ERROR_RETURN_FIX */ if ((retval >= 0) && (_putc_nolock('\0', outfile) != EOF)) { return (retval); } string[0] = 0; return -1; #endif /* _SWPRINTFS_ERROR_RETURN_FIX */ }
intptr_t __cdecl _tfindfirst64i32( const _TSCHAR * szWild, struct _tfinddata64i32_t * pfd ) #endif /* _USE_INT64 */ { WIN32_FIND_DATA wfd; HANDLE hFile; DWORD err; _VALIDATE_RETURN( (pfd != NULL), EINVAL, -1); /* We assert to make sure the underlying Win32 struct WIN32_FIND_DATA's cFileName member doesn't have an array size greater than ours */ _VALIDATE_RETURN( (sizeof(pfd->name) <= sizeof(wfd.cFileName)), ENOMEM, -1); _VALIDATE_RETURN( (szWild != NULL), EINVAL, -1); if ((hFile = FindFirstFile(szWild, &wfd)) == INVALID_HANDLE_VALUE) { err = GetLastError(); switch (err) { case ERROR_NO_MORE_FILES: case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: errno = ENOENT; break; case ERROR_NOT_ENOUGH_MEMORY: errno = ENOMEM; break; default: errno = EINVAL; break; } return (-1); } pfd->attrib = (wfd.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) ? 0 : wfd.dwFileAttributes; pfd->time_create = __time64_t_from_ft(&wfd.ftCreationTime); pfd->time_access = __time64_t_from_ft(&wfd.ftLastAccessTime); pfd->time_write = __time64_t_from_ft(&wfd.ftLastWriteTime); #if _USE_INT64 pfd->size = ((__int64)(wfd.nFileSizeHigh)) * (0x100000000i64) + (__int64)(wfd.nFileSizeLow); #else /* _USE_INT64 */ pfd->size = wfd.nFileSizeLow; #endif /* _USE_INT64 */ _ERRCHECK(_tcscpy_s(pfd->name, _countof(pfd->name), wfd.cFileName)); return ((intptr_t)hFile); }
// Gets the file position in the internal fpos_t format. The returned value // should only be used in a call to fsetpos(). Our implementation happens to // just wrap _ftelli64() and _fseeki64(). Return zero on success; returns -1 // and sets errno on failure. extern "C" int __cdecl fgetpos(FILE* const stream, fpos_t* const position) { _VALIDATE_RETURN(stream != nullptr, EINVAL, -1); _VALIDATE_RETURN(position != nullptr, EINVAL, -1); *position = _ftelli64(stream); if (*position == -1) return -1; return 0; }
extern "C" size_t __cdecl _mbstrnlen_l( char const* const string, size_t const max_size, _locale_t const locale ) { _VALIDATE_RETURN(string != nullptr, EINVAL, static_cast<size_t>(-1)); _VALIDATE_RETURN(max_size <= INT_MAX, EINVAL, static_cast<size_t>(-1)); return common_mbstrlen_l(string, max_size, locale); }
/*** *char *bsearch() - do a binary search on an array * *Purpose: * Does a binary search of a sorted array for a key. * *Entry: * const char *key - key to search for * const char *base - base of sorted array to search * unsigned int num - number of elements in array * unsigned int width - number of bytes per element * int (*compare)() - pointer to function that compares two array * elements, returning neg when #1 < #2, pos when #1 > #2, and * 0 when they are equal. Function is passed pointers to two * array elements. * *Exit: * if key is found: * returns pointer to occurrence of key in array * if key is not found: * returns NULL * *Exceptions: * Input parameters are validated. Refer to the validation section of the function. * *******************************************************************************/ #ifdef __USE_CONTEXT #define __COMPARE(context, p1, p2) (*compare)(context, p1, p2) #else /* __USE_CONTEXT */ #define __COMPARE(context, p1, p2) (*compare)(p1, p2) #endif /* __USE_CONTEXT */ #if !defined (_M_CEE) _CRTIMP #endif /* !defined (_M_CEE) */ #ifdef __USE_CONTEXT void * __fileDECL bsearch_s ( REG4 const void *key, const void *base, size_t num, size_t width, int (__fileDECL *compare)(void *, const void *, const void *), void *context ) #else /* __USE_CONTEXT */ void * __fileDECL bsearch ( REG4 const void *key, const void *base, size_t num, size_t width, int (__fileDECL *compare)(const void *, const void *) ) #endif /* __USE_CONTEXT */ { REG1 char *lo = (char *)base; REG2 char *hi = (char *)base + (num - 1) * width; REG3 char *mid; size_t half; int result; /* validation section */ _VALIDATE_RETURN(base != NULL || num == 0, EINVAL, NULL); _VALIDATE_RETURN(width > 0, EINVAL, NULL); _VALIDATE_RETURN(compare != NULL, EINVAL, NULL); /* We allow a NULL key here because it breaks some older code and because we do not dereference this ourselves so we can't be sure that it's a problem for the comparison function */ while (lo <= hi) { if ((half = num / 2) != 0) { mid = lo + (num & 1 ? half : (half - 1)) * width; if (!(result = __COMPARE(context, key, mid))) return(mid); else if (result < 0) { hi = mid - width; num = num & 1 ? half : half-1; } else { lo = mid + width; num = half; } } else if (num) return (__COMPARE(context, key, lo) ? NULL : lo); else break; } return NULL; }
extern "C" int __cdecl _memicmp( const void* first, const void* last, size_t count ) { if (__locale_changed == 0) { /* validation section */ _VALIDATE_RETURN(first != NULL || count == 0, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(last != NULL || count == 0, EINVAL, _NLSCMPERROR); return __ascii_memicmp(first, last, count); } else { return _memicmp_l(first, last, count, NULL); } }
unsigned char * __cdecl _mbsnbcpy_l( unsigned char *dst, const unsigned char *src, size_t cnt, _locale_t plocinfo ) { unsigned char *start = dst; _LocaleUpdate _loc_update(plocinfo); /* validation section */ _VALIDATE_RETURN(dst != NULL || cnt == 0, EINVAL, NULL); _VALIDATE_RETURN(src != NULL || cnt == 0, EINVAL, NULL); _BEGIN_SECURE_CRT_DEPRECATION_DISABLE if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return (unsigned char *)strncpy((char *)dst, (const char *)src, cnt); _END_SECURE_CRT_DEPRECATION_DISABLE while (cnt) { cnt--; if ( _ismbblead_l(*src, _loc_update.GetLocaleT()) ) { *dst++ = *src++; if (!cnt) { dst[-1] = '\0'; break; } cnt--; if ((*dst++ = *src++) == '\0') { dst[-2] = '\0'; break; } } else if ((*dst++ = *src++) == '\0') break; } /* pad with nulls as needed */ while (cnt--) *dst++ = '\0'; return start; }
intptr_t __cdecl _tspawnv ( int modeflag, const _TSCHAR *pathname, const _TSCHAR * const *argv ) { /* validation section */ _VALIDATE_RETURN(pathname != NULL, EINVAL, -1); _VALIDATE_RETURN(*pathname != _T('\0'), EINVAL, -1); _VALIDATE_RETURN(argv != NULL, EINVAL, -1); _VALIDATE_RETURN(*argv != NULL, EINVAL, -1); _VALIDATE_RETURN(**argv != _T('\0'), EINVAL, -1); return(_tspawnve(modeflag,pathname,argv,NULL)); }
extern "C" int __cdecl _strnicmp( const char* dst, const char* src, size_t count ) { if (__locale_changed == 0) { /* validation section */ _VALIDATE_RETURN(dst != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(src != NULL, EINVAL, _NLSCMPERROR); _VALIDATE_RETURN(count <= INT_MAX, EINVAL, _NLSCMPERROR); return __ascii_strnicmp(dst, src, count); } else { return _strnicmp_l(dst, src, count, NULL); } }
int __cdecl _tfindnext64i32(intptr_t hFile, struct _tfinddata64i32_t * pfd) #endif /* _USE_INT64 */ { WIN32_FIND_DATA wfd; DWORD err; _VALIDATE_RETURN( ((HANDLE)hFile != INVALID_HANDLE_VALUE), EINVAL, -1); _VALIDATE_RETURN( (pfd != NULL), EINVAL, -1); _VALIDATE_RETURN( (sizeof(pfd->name) <= sizeof(wfd.cFileName)), ENOMEM, -1); if (!FindNextFile((HANDLE)hFile, &wfd)) { err = GetLastError(); switch (err) { case ERROR_NO_MORE_FILES: case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: errno = ENOENT; break; case ERROR_NOT_ENOUGH_MEMORY: errno = ENOMEM; break; default: errno = EINVAL; break; } return (-1); } pfd->attrib = (wfd.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) ? 0 : wfd.dwFileAttributes; pfd->time_create = __time64_t_from_ft(&wfd.ftCreationTime); pfd->time_access = __time64_t_from_ft(&wfd.ftLastAccessTime); pfd->time_write = __time64_t_from_ft(&wfd.ftLastWriteTime); #if _USE_INT64 pfd->size = ((__int64)(wfd.nFileSizeHigh)) * (0x100000000i64) + (__int64)(wfd.nFileSizeLow); #else /* _USE_INT64 */ pfd->size = wfd.nFileSizeLow; #endif /* _USE_INT64 */ _ERRCHECK(_tcscpy_s(pfd->name, _countof(pfd->name), wfd.cFileName)); return (0); }