slibc
Functions
string_templates_.hpp File Reference

Contains overloaded templates for some _s-functions defined in string.h. More...

#include "./string.h"

Go to the source code of this file.

Functions

template<rsize_t s1max>
errno_t strcpy_s (char(&s1)[s1max], const char *restrict s2)
 The strcpy_s template function copies the string s2 to s1.
template<rsize_t s1max>
errno_t strncpy_s (char(&s1)[s1max], const char *restrict s2, rsize_t n)
 The strncpy_s template function copies the string s2 to s1.
template<rsize_t s1max>
errno_t strcat_s (char(&s1)[s1max], const char *restrict s2)
 The strcat_s template function copies the string s2 to the end of s1.
template<rsize_t s1max>
errno_t strncat_s (char(&s1)[s1max], const char *restrict s2, rsize_t n)
 The strncat_s template function copies not more than n characters of the string s2 to the end of s1.

Detailed Description

Contains overloaded templates for some _s-functions defined in string.h.

The usage of these templates is restricted to C++. this file is included automatically, if the macro _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES is defined. It's not necessary to declare the size of the destination buffer, when the overloaded functions are available (only if the compiler can calculate the size automatically).

The overloaded templates make the _s-functions easier to use. Buffer sizes, which are declared in the _s-functions, are already known at compilation time. This can be used by C++ templates.

Usage Example:

         char buf[10];
         char *input = "123456789ABCDEF";
         // ContstraintHandler is called, because the input 
         // contains more than 10 characters
         strcpy_s(buf, input)

As you can see it's not necessary to explicitly declare the size-parameter (usually one has to write strcpy_s(buf, sizeof(buf), input)). This feature enhances the useability (less to write) and the migration process to the new _s-functions.


Function Documentation

template<rsize_t s1max>
errno_t strcat_s ( char(&)  s1[s1max],
const char *restrict  s2 
)

The strcat_s template function copies the string s2 to the end of s1.

For statically allocated destination buffers this C++ template function automatically deducts strcat_s' size argument s1max.

Parameters:
[in,out]s1The destination buffer
[in]s2The source string
Returns:
0 if there was no runtime-constraint violation. Otherwise a non-zero value is returned.

References strcat_s().

template<rsize_t s1max>
errno_t strcpy_s ( char(&)  s1[s1max],
const char *restrict  s2 
)

The strcpy_s template function copies the string s2 to s1.

For statically allocated destination buffers this C++ template function automatically deducts strcpy_s' size argument s1max.

Parameters:
[out]s1The destination buffer
[in]s2The source string
Returns:
0 if there was no runtime-constraint violation. Otherwise a non-zero value is returned.

References strcpy_s().

template<rsize_t s1max>
errno_t strncat_s ( char(&)  s1[s1max],
const char *restrict  s2,
rsize_t  n 
)

The strncat_s template function copies not more than n characters of the string s2 to the end of s1.

For statically allocated destination buffers this C++ template function automatically deducts strncat_s' size argument s1max.

Parameters:
[in,out]s1The destination buffer
[in]s2The source string
[in]nMaximum amount of characters that should be copied. (If s2 is shorter than n, less bytes are copied)
Returns:
0 if there was no runtime-constraint violation. Otherwise a non-zero value is returned.

References strncat_s().

template<rsize_t s1max>
errno_t strncpy_s ( char(&)  s1[s1max],
const char *restrict  s2,
rsize_t  n 
)

The strncpy_s template function copies the string s2 to s1.

For statically allocated destination buffers this C++ template function automatically deducts strncpy_s' size argument s1max.

Parameters:
[out]s1The destination buffer
[in]s2The source string
[in]nMaximum amount of characters that should be copied. (If s2 is shorter than n, less bytes are copied)
Returns:
0 if there was no runtime-constraint violation. Otherwise a non-zero value is returned.

References strncpy_s().