Share via


Security-Enhanced Versions of CRT Functions

More secure versions of run-time library routines are available since Visual C++ 2005. For further information concerning Security Enhancements in the CRT, see Security Enhancements in the CRT.

Secure Functions

Function

Use

.NET Framework equivalent

_access_s, _waccess_s

Determine file-access permission

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_malloca

Allocates memory on the stack

Not applicable

asctime_s, _wasctime_s

Convert time from type struct tm to character string

System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString

bsearch_s

Performs a binary search of a sorted array

BinarySearch

_cgets_s, _cgetws_s

Get a character string from the console

Not applicable

_chsize_s

Changes the size of a file

clearerr_s

Resets the error indicator for a stream

  • Not applicable

_controlfp_s

Get and set the floating-point control word

  • Not applicable

_cprintf_s, _cprintf_s_l, _cwprintf_s, _cwprintf_s_l

Formats and prints to the console

  • Not applicable

_cscanf_s, _cscanf_s_l, _cwscanf_s, _cwscanf_s_l

Reads formatted data from the console

  • Not applicable

_ctime_s, _ctime32_s, _ctime64_s, _wctime_s, _wctime32_s, _wctime64_s

Convert time from type time_t, __time32_t or __time64_t to character string

System::DateTime::GetDateTimeFormats, System::DateTime::ToString, System::DateTime::ToLongTimeString, System::DateTime::ToShortTimeString

_ecvt_s

Converts a double number to a string

System::Convert::ToString

_fcvt_s

Converts a floating-point number to a string

ToString

fopen_s, _wfopen_s

Open a file

fprintf_s, _fprintf_s_l, fwprintf_s, _fwprintf_s_l

Print formatted data to a stream

System::IO::StreamWriter::Write

freopen_s, _wfreopen_s

Reassign a file pointer

fscanf_s, _fscanf_s_l, fwscanf_s, _fwscanf_s_l

Read formatted data from a stream

_ftime_s, _ftime32_s, _ftime64_s

Get the current time

System::DateTime::Now

_gcvt_s

Converts a floating-point value to a string, which it stores in a buffer

ToString

getenv_s, _wgetenv_s

Get a value from the current environment.

System::Environment::GetEnvironmentVariable

gets_s, _getws_s

Get a line from the stdin stream

System::Console::Read

_gmtime32_s, _gmtime64_s

Convert time from type time_t to structtm or from type __time64_t to struct tm

System::DateTime::UtcNow, System::DateTime::ToUniversalTime

_itoa_s, _i64toa_s, _ui64toa_s, _itow_s, _i64tow_s, _ui64tow_s

Convert an integer to a string

System::Convert::ToString

_lfind_s

Performs a linear search for the specified key

System::Collections::ArrayList::Contains

localtime_s, _localtime32_s, _localtime64_s

Convert time from type time_t to struct tm or from type __time64_t to struct tmwith local correction

System::DateTime::ToLocalTime

_lsearch_s

Performs a linear search for a value; adds to end of list if not found

Not applicable

_ltoa_s, _ltow_s

Convert a long integer to a string

System::Convert::ToString

_makepath_s, _wmakepath_s

Create a path name from components

System::IO::File::Create

_mbccpy_s, _mbccpy_s_l

Copies a multibyte character from one string to another string

Not applicable

_mbsnbcat_s, _mbsnbcat_s_l

Appends, at most, the first n bytes of one multibyte character string to another

Not applicable

_mbsnbcpy_s, _mbsnbcpy_s_l

Copies n bytes of a string to a destination string

Not applicable

mbsrtowcs_s

Converts a multibyte character string to a corresponding wide characters string

Not applicable

mbstowcs_s, _mbstowcs_s_l

Converts a sequence of multibyte characters to a corresponding sequence of wide characters

Not applicable

memcpy_s, wmemcpy_s

Copies characters between buffers

Not applicable

memmove_s, wmemmove_s

Moves one buffer to another

Not applicable

_mktemp_s, _wmktemp_s

Create a unique filename

Not applicable

printf_s, _printf_s_l, wprintf_s, _wprintf_s_l

Print formatted output to the standard output stream

_putenv_s, _wputenv_s

Create, modify, or remove environment variables

  • Not applicable

qsort_s

Performs a quick sort

System::Collections::ArrayList::Sort

rand_s

Generates a pseudorandom number

System::Random Class

scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l

Read formatted data from the standard input stream

System::Console::Read, System::Console::ReadLine, see also Parse methods, such as System::Double::Parse

_searchenv_s, _wsearchenv_s

Search for a file using environment paths

Not applicable

_snprintf_s, _snprintf_s_l, _snwprintf_s, _snwprintf_s_l

Write formatted data to a string

Not applicable

_snscanf_s, _snscanf_s_l, _snwscanf_s, _snwscanf_s_l

Read formatted data of a specified length from a string.

Not applicable

_sopen_s, _wsopen_s

Open a file for sharing

Not applicable

_splitpath_s, _wsplitpath_s

Break a path name into components

Not applicable

sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l

Write formatted data to a string

System::String::Format

sscanf_s, _sscanf_s_l, swscanf_s, _swscanf_s_l

Read formatted data from a string

See Parse methods, such as System::Double::Parse

strcat_s, wcscat_s, _mbscat_s

Append a string

System::String::Concat

strcpy_s, wcscpy_s, _mbscpy_s

Copy a string

System::String::Copy

_strdate_s, _wstrdate_s

Return current system date as string

System::DateTime::Parse

strerror_s, _strerror_s, _wcserror_s, __wcserror_s

Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror)

System::Exception::Message

_strlwr_s, _strlwr_s_l, _mbslwr_s, _mbslwr_s_l, _wcslwr_s, _wcslwr_s_l

Convert a string to lowercase

System::String::ToLower

strncat_s, _strncat_s_l, wcsncat_s, _wcsncat_s_l, _mbsncat_s, _mbsncat_s_l

Append characters to a string

System::String::Concat

strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l

Copy characters of one string to another

System::String::Copy

_strtime_s, _wstrtime_s

Return current system time as string

System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString

strtok_s, _strtok_s_l, wcstok_s, _wcstok_s_l, _mbstok_s, _mbstok_s_l

Find the next token in a string, using the current locale or a locale passed in

Not applicable

_strupr_s, _strupr_s_l, _mbsupr_s, _mbsupr_s_l, _wcsupr_s, _wcsupr_s_l

Convert a string to uppercase

System::String::ToUpper

tmpfile_s

Creates a temporary file

Not applicable

tmpnam_s, _wtmpnam_s

Generate names you can use to create temporary files

Not applicable

_ultoa_s, _ultow_s

Convert an unsigned long integer to a string

System::Convert::ToString

_umask_s

Sets the default file-permission mask

System::IO::File::SetAttributes

_vcprintf_s, _vcprintf_s_l, _vcwprintf_s, _vcwprintf_s_l

Write formatted output to the console using a pointer to a list of arguments

System::Console::Write

vfprintf_s, _vfprintf_s_l, vfwprintf_s, _vfwprintf_s_l

Write formatted output using a pointer to a list of arguments

Not applicable

vprintf_s, _vprintf_s_l, vwprintf_s, _vwprintf_s_l

Write formatted output using a pointer to a list of arguments

System::Console::Write

vsnprintf_s, _vsnprintf_s, _vsnprintf_s_l, _vsnwprintf_s, _vsnwprintf_s_l

Write formatted output using a pointer to a list of arguments

Not applicable

vsprintf_s, _vsprintf_s_l, vswprintf_s, _vswprintf_s_l

Write formatted output using a pointer to a list of arguments

System::String::Format

wcrtomb_s

Convert a wide character into its multibyte character representation

Not applicable

wcsrtombs_s

Convert a wide character string to its multibyte character string representation

Not applicable

wcstombs_s, _wcstombs_s_l

Converts a sequence of wide characters to a corresponding sequence of multibyte characters

Not applicable

wctomb_s, _wctomb_s_l

Converts a wide character to the corresponding multibyte character

Not applicable

See Also

Reference

C Run-Time Libraries