blocxx
Namespaces | Defines | Functions | Variables

SafeCString.hpp File Reference

#include "blocxx/BLOCXX_config.h"
#include <cstddef>
#include <cstdarg>
#include <cstdio>
#include "blocxx/Exception.hpp"

Go to the source code of this file.

Namespaces

namespace  BLOCXX_NAMESPACE
 

Taken from RFC 1321.


namespace  BLOCXX_NAMESPACE::SafeCString
namespace  BLOCXX_NAMESPACE::SafeCString::Impl

Defines

#define BLOCXX_INTSTR_AUX(x)   # x
#define BLOCXX_INTSTR(x)   BLOCXX_INTSTR_AUX(x)

Functions

char * BLOCXX_NAMESPACE::SafeCString::str_dup (char const *s)
 Like std::strdup, except that new is used to allocate memory.
char * BLOCXX_NAMESPACE::SafeCString::str_dup_nothrow (char const *s)
 Like std::strdup, except that no-throw new is used to allocate memory and NULL is returned on allocation failure.
char const * BLOCXX_NAMESPACE::SafeCString::nonull (char const *s)
 RETURNS: s if s is nonnull, otherwise returns empty string.
char * BLOCXX_NAMESPACE::SafeCString::strcpy_trunc (char *dst, std::size_t dstsize, char const *src)
 PROMISE: copies the first n = min(strlen(src), dstsize - 1) characters of C-string src to dst, null-terminating the result.
char * BLOCXX_NAMESPACE::SafeCString::strcpy_trunc (char *dst, std::size_t dstsize, char const *src, std::size_t srclen)
 PROMISE: copies the first n = min(strlen(src), srclen, dstsize - 1) characters of C-string src to dst, null-terminating the result.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcpy_trunc (char(&dst)[N], char const *src)
 A variant of strcpy_trunc that infers the destination buffer size.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcpy_trunc (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcpy_trunc that infers the destination buffer size.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::strcpy_to_pos_trunc (char(&dst)[N], std::size_t pos, char const *src)
 Like strcpy_trunc, but the destination is the subarray dst[pos..N-1] and the return value is an array index instead of a char *.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::strcpy_to_pos_trunc (char(&dst)[N], std::size_t pos, char const *src, std::size_t srclen)
 Like strcpy_trunc, but the destination is the subarray dst[pos..N-1] and the return value is an array index instead of a char *.
 BLOCXX_NAMESPACE::SafeCString::BLOCXX_DECLARE_EXCEPTION (Overflow)
char * BLOCXX_NAMESPACE::SafeCString::strcpy_check (char *dst, std::size_t dstsize, char const *src)
 PROMISE: copies the first n = min(strlen(src), dstsize - 1) chars of the C-string src to dst and appends a terminating '\0'.
char * BLOCXX_NAMESPACE::SafeCString::strcpy_check (char *dst, std::size_t dstsize, char const *src, std::size_t srclen)
 PROMISE: copies the first min(n, dstsize - 1) chars of the C-string src to dst, where n = min(strlen(src), srclen), and appends a terminating '\0'.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcpy_check (char(&dst)[N], char const *src)
 A variant of strcpy_check that infers the destination buffer size.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcpy_check (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcpy_check that infers the destination buffer size.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::strcpy_to_pos_check (char(&dst)[N], std::size_t pos, char const *src)
 Like strcpy_check, but the destination is the subarray dst[pos..N-1] and the return value is an array index instead of a char *.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::strcpy_to_pos_check (char(&dst)[N], std::size_t pos, char const *src, std::size_t srclen)
 Like strcpy_check, but the destination is the subarray dst[pos..N-1] and the return value is an array index instead of a char *.
char * BLOCXX_NAMESPACE::SafeCString::strcat_trunc (char *dst, std::size_t dstsize, char const *src)
 PROMISE: If dst[0..dstsize-1] contains a '\0', appends to C-string dst the first min(strlen(src), dstsize - 1 - strlen(dst)) characters of C-string src, and null terminates the result.
char * BLOCXX_NAMESPACE::SafeCString::strcat_trunc (char *dst, std::size_t dstsize, char const *src, std::size_t srclen)
 PROMISE: If dst[0..dstsize-1] contains a '\0', appends to C-string dst the first min(strlen(src), srclen, dstsize - 1 - strlen(dst)) characters of C-string src, and null terminates the result.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcat_trunc (char(&dst)[N], char const *src)
 A variant of strcat_trunc that infers the destination buffer size.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcat_trunc (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcat_trunc that infers the destination buffer size.
char * BLOCXX_NAMESPACE::SafeCString::strcat_check (char *dst, std::size_t dstsize, char const *src)
 PROMISE: If dst[0..dstsize-1] contains a '\0', appends to C-string dst the first min(strlen(src), dstsize - 1 - strlen(dst)) characters of C-string src and null terminates the result.
char * BLOCXX_NAMESPACE::SafeCString::strcat_check (char *dst, std::size_t dstsize, char const *src, std::size_t srclen)
 PROMISE: If dst[0..dstsize-1] contains a '\0', appends to C-string dst the first min(N, dstsize - 1 - strlen(dst)) characters of C-string src, where N = min(strlen(src), srclen), and null terminates the result.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcat_check (char(&dst)[N], char const *src)
 A variant of strcat_check that infers the destination buffer size.
template<std::size_t N>
char * BLOCXX_NAMESPACE::SafeCString::strcat_check (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcat_check that infers the destination buffer size.
std::size_t BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output (int retval, std::size_t dstsize)
std::size_t BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check (int retval, std::size_t dstsize)
template<typename T1 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 , typename T4 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4, T5 const &x5)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<std::size_t N, typename T1 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char(&dst)[N], char const *fmt, T1 const &x1)
 A variant of sprintf_trunc that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2)
 A variant of sprintf_trunc that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3)
 A variant of sprintf_trunc that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 , typename T4 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4)
 A variant of sprintf_trunc that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_trunc (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4, T5 const &x5)
 A variant of sprintf_trunc that infers the destination buffer size.
template<typename T1 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 , typename T4 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char *dst, std::size_t dstsize, char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4, T5 const &x5)
 PROMISE: Behaves like sprintf(dst, fmt, ...) except that output stops at dstsize - 1 characters.
template<std::size_t N, typename T1 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char(&dst)[N], char const *fmt, T1 const &x1)
 A variant of sprintf_check that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2)
 A variant of sprintf_check that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3)
 A variant of sprintf_check that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 , typename T4 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4)
 A variant of sprintf_check that infers the destination buffer size.
template<std::size_t N, typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
std::size_t BLOCXX_NAMESPACE::SafeCString::sprintf_check (char(&dst)[N], char const *fmt, T1 const &x1, T2 const &x2, T3 const &x3, T4 const &x4, T5 const &x5)
 A variant of sprintf_check that infers the destination buffer size.
template<typename T1 >
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_trunc (char *dst, std::size_t dstsize, char const *fmt, va_list ap)
 PROMISE: Behaves like vprintf(dst, fmt, ap) except that output stops at dstsize - 1 characters.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_trunc (char(&dst)[N], char const *fmt, va_list ap)
 A variant of vprintf_trunc that infers the destination buffer size.
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_check (char *dst, std::size_t dstsize, char const *fmt, va_list ap)
 PROMISE: Behaves like vprintf(dst, fmt, ap) except that output stops at dstsize - 1 characters.
template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_check (char(&dst)[N], char const *fmt, va_list ap)
 A variant of vprintf_check that infers the destination buffer size.

Variables

int const BLOCXX_NAMESPACE::SafeCString::RESULT_TRUNCATED = 0
 Error codes for use with OverflowException class.
int const BLOCXX_NAMESPACE::SafeCString::DEST_UNTERMINATED = 1

Define Documentation

#define BLOCXX_INTSTR (   x)    BLOCXX_INTSTR_AUX(x)

Definition at line 730 of file SafeCString.hpp.

#define BLOCXX_INTSTR_AUX (   x)    # x

Definition at line 720 of file SafeCString.hpp.