blocxx
Namespaces | Functions | Variables

BLOCXX_NAMESPACE::SafeCString Namespace Reference

Namespaces

namespace  Impl

Functions

 BLOCXX_DEFINE_EXCEPTION (Overflow)
char * str_dup (char const *s)
 Like std::strdup, except that new is used to allocate memory.
char * 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 * 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 * 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.
char * 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 * 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'.
char * 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 * 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.
char * 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 * 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.
char const * nonull (char const *s)
 RETURNS: s if s is nonnull, otherwise returns empty string.
template<std::size_t N>
char * 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 * 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 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 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_DECLARE_EXCEPTION (Overflow)
template<std::size_t N>
char * 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 * 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 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 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 *.
template<std::size_t N>
char * 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 * strcat_trunc (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcat_trunc that infers the destination buffer size.
template<std::size_t N>
char * 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 * strcat_check (char(&dst)[N], char const *src, std::size_t srclen)
 A variant of strcat_check that infers the destination buffer size.
template<typename T1 >
std::size_t 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 vprintf_check (char(&dst)[N], char const *fmt, va_list ap)
 A variant of vprintf_check that infers the destination buffer size.
char * fgets_trunc (char *dst, std::size_t dstsize, FILE *fp)
char * fgets_check (char *dst, std::size_t dstsize, FILE *fp)
String fget_string (FILE *fp, std::size_t const max_chars)
char * fgets_trunc (char *dst, std::size_t dstsize, std::FILE *fp)
 PROMISE: Equivalent to std::fgets, except that I/O errors are reported by throwing an exception.
template<std::size_t N>
char * fgets_trunc (char(&dst)[N], std::FILE *fp)
 A variant of fgets_trunc that infers the destination buffer size.
char * fgets_check (char *dst, std::size_t dstsize, std::FILE *fp)
 PROMISE: Equivalent to std::fgets, except that I/O errors and truncated lines are reported by throwing an exception.
template<std::size_t N>
char * fgets_check (char(&dst)[N], std::FILE *fp)
 A variant of fgets_check that infers the destination buffer size.
String fget_string (std::FILE *fp, std::size_t max_chars)
 RETURNS: A String created by reading from fp until either EOF or a newline is encountered.

Variables

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

Function Documentation

BLOCXX_NAMESPACE::SafeCString::BLOCXX_DECLARE_EXCEPTION ( Overflow  )
BLOCXX_NAMESPACE::SafeCString::BLOCXX_DEFINE_EXCEPTION ( Overflow  )
String BLOCXX_NAMESPACE::SafeCString::fget_string ( FILE *  fp,
std::size_t const  max_chars 
)
String BLOCXX_NAMESPACE::SafeCString::fget_string ( std::FILE *  fp,
std::size_t  max_chars 
)

RETURNS: A String created by reading from fp until either EOF or a newline is encountered.

If a newline is found it is included in the return String.

THROWS: blocxx::IOException if there is a read error.

THROWS: blocxx::StringConversionException if neither EOF nor newline is found within max_chars characters. (This is a protection against unreasonably long inputs.)

char* BLOCXX_NAMESPACE::SafeCString::fgets_check ( char *  dst,
std::size_t  dstsize,
FILE *  fp 
)

Definition at line 67 of file SafeCStringIO.cpp.

References BLOCXX_THROW, BLOCXX_THROW_ERR, and RESULT_TRUNCATED.

Referenced by fgets_check().

char* BLOCXX_NAMESPACE::SafeCString::fgets_check ( char *  dst,
std::size_t  dstsize,
std::FILE *  fp 
)

PROMISE: Equivalent to std::fgets, except that I/O errors and truncated lines are reported by throwing an exception.

THROWS: blocxx::IOException if there is a read error.

THROWS: OverflowException if the input line (including terminating '\0') must be truncated to fit into dstsize chars.

REQUIRES: dst nonnull, fp nonnull, dstsize > 0.

RETURNS: NULL if no characters read because of reaching EOF; dst otherwise.

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::fgets_check ( char(&)  dst[N],
std::FILE *  fp 
) [inline]

A variant of fgets_check that infers the destination buffer size.

Definition at line 91 of file SafeCStringIO.hpp.

References fgets_check().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::fgets_trunc ( char(&)  dst[N],
std::FILE *  fp 
) [inline]

A variant of fgets_trunc that infers the destination buffer size.

Definition at line 67 of file SafeCStringIO.hpp.

References fgets_trunc().

char* BLOCXX_NAMESPACE::SafeCString::fgets_trunc ( char *  dst,
std::size_t  dstsize,
std::FILE *  fp 
)

PROMISE: Equivalent to std::fgets, except that I/O errors are reported by throwing an exception.

THROWS: blocxx::IOException if there is a read error.

REQUIRES: dst nonnull, fp nonnull, dstsize > 0.

RETURNS: NULL if no characters read because of reaching EOF; dst otherwise.

char* BLOCXX_NAMESPACE::SafeCString::fgets_trunc ( char *  dst,
std::size_t  dstsize,
FILE *  fp 
)

Definition at line 53 of file SafeCStringIO.cpp.

References BLOCXX_THROW.

Referenced by fget_string(), and fgets_trunc().

char const* BLOCXX_NAMESPACE::SafeCString::nonull ( char const *  s) [inline]

RETURNS: s if s is nonnull, otherwise returns empty string.

WARNING: Do not deallocate the return value.

Definition at line 74 of file SafeCString.hpp.

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.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 532 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 548 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 566 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 584 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 602 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 615 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 624 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 635 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 647 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 660 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

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.

Definition at line 488 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Definition at line 500 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Definition at line 513 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Definition at line 477 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 439 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 393 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Definition at line 468 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 407 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 423 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 455 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

BLOCXX_COMMON_API char * BLOCXX_NAMESPACE::SafeCString::str_dup ( char const *  s)

Like std::strdup, except that new is used to allocate memory.

Definition at line 107 of file SafeCString.cpp.

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.

Definition at line 113 of file SafeCString.cpp.

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.

THROWS: OverflowException with getErrorCode() == DEST_UNTERMINATED if dst[0..dstsize-1] contains no '\0'.

THROWS: OverflowException with getErrorCode() == RESULT_TRUNCATED if strlen(dst) + N >= dstsize.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least srclen characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' of the resulting C-string.

Definition at line 204 of file SafeCString.cpp.

References strcpy_check().

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.

THROWS: OverflowException with getErrorCode() == DEST_UNTERMINATED if dst[0..dstsize-1] contains no '\0'.

THROWS: OverflowException with getErrorCode() == RESULT_TRUNCATED if strlen(dst) + strlen(src) >= dstsize.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' of the resulting C-string.

Definition at line 198 of file SafeCString.cpp.

References strcpy_check().

Referenced by strcat_check().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcat_check ( char(&)  dst[N],
char const *  src,
std::size_t  srclen 
) [inline]

A variant of strcat_check that infers the destination buffer size.

Definition at line 367 of file SafeCString.hpp.

References strcat_check().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcat_check ( char(&)  dst[N],
char const *  src 
) [inline]

A variant of strcat_check that infers the destination buffer size.

Definition at line 358 of file SafeCString.hpp.

References strcat_check().

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.

THROWS: OverflowException if dst[0..dstsize-1] contains no '\0'.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' of the resulting C-string.

Definition at line 184 of file SafeCString.cpp.

References strcpy_trunc().

Referenced by strcat_trunc().

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.

THROWS: OverflowException if dst[0..dstsize-1] contains no '\0'.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least srclen characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' of the resulting C-string

Definition at line 190 of file SafeCString.cpp.

References strcpy_trunc().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcat_trunc ( char(&)  dst[N],
char const *  src 
) [inline]

A variant of strcat_trunc that infers the destination buffer size.

Definition at line 291 of file SafeCString.hpp.

References strcat_trunc().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcat_trunc ( char(&)  dst[N],
char const *  src,
std::size_t  srclen 
) [inline]

A variant of strcat_trunc that infers the destination buffer size.

Definition at line 300 of file SafeCString.hpp.

References strcat_trunc().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcpy_check ( char(&)  dst[N],
char const *  src,
std::size_t  srclen 
) [inline]

A variant of strcpy_check that infers the destination buffer size.

Definition at line 216 of file SafeCString.hpp.

References strcpy_check().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcpy_check ( char(&)  dst[N],
char const *  src 
) [inline]

A variant of strcpy_check that infers the destination buffer size.

Definition at line 207 of file SafeCString.hpp.

References strcpy_check().

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'.

THROWS: OverflowException if strlen(src) >= dstsize.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least dstsize characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' char.

Definition at line 155 of file SafeCString.cpp.

References BLOCXX_THROW_ERR, and RESULT_TRUNCATED.

Referenced by BLOCXX_NAMESPACE::FileSystem::createAutoDeleteTempFile(), BLOCXX_NAMESPACE::FileSystem::createTempFile(), strcat_check(), strcpy_check(), and strcpy_to_pos_check().

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'.

THROWS: OverflowException if n >= dstsize.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least srclen characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: Pointer to the terminating '\0' char.

Definition at line 170 of file SafeCString.cpp.

References strcpy_check(), and strcpy_trunc().

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 
) [inline]

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 *.

Definition at line 238 of file SafeCString.hpp.

References strcpy_check().

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 
) [inline]

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 *.

Definition at line 226 of file SafeCString.hpp.

References strcpy_check().

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 
) [inline]

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 *.

Definition at line 151 of file SafeCString.hpp.

References strcpy_trunc().

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 
) [inline]

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 *.

Definition at line 139 of file SafeCString.hpp.

References strcpy_trunc().

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcpy_trunc ( char(&)  dst[N],
char const *  src 
) [inline]

A variant of strcpy_trunc that infers the destination buffer size.

Definition at line 120 of file SafeCString.hpp.

References strcpy_trunc().

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.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least dstsize - 1 characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: dst + n.

Definition at line 123 of file SafeCString.cpp.

Referenced by strcat_trunc(), strcpy_check(), strcpy_to_pos_trunc(), and strcpy_trunc().

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.

REQUIRE: dst != 0, src != 0, dstsize > 0.

REQUIRE: dst points to an array of at least dstsize characters.

REQUIRE: src points to a null-terminated array of characters or an array of at least srclen characters.

REQUIRE: the source and destination character sequences do not overlap.

RETURNS: dst + n.

Definition at line 138 of file SafeCString.cpp.

template<std::size_t N>
char* BLOCXX_NAMESPACE::SafeCString::strcpy_trunc ( char(&)  dst[N],
char const *  src,
std::size_t  srclen 
) [inline]

A variant of strcpy_trunc that infers the destination buffer size.

Definition at line 129 of file SafeCString.hpp.

References strcpy_trunc().

std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_check ( char *  dst,
std::size_t  dstsize,
char const *  fmt,
va_list  ap 
) [inline]

PROMISE: Behaves like vprintf(dst, fmt, ap) except that output stops at dstsize - 1 characters.

Always outputs a terminating '\0'.

THROWS: OverflowException if the output had to be truncated.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 701 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check().

Referenced by vprintf_check().

template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_check ( char(&)  dst[N],
char const *  fmt,
va_list  ap 
) [inline]

A variant of vprintf_check that infers the destination buffer size.

Definition at line 712 of file SafeCString.hpp.

References vprintf_check().

template<std::size_t N>
std::size_t BLOCXX_NAMESPACE::SafeCString::vprintf_trunc ( char(&)  dst[N],
char const *  fmt,
va_list  ap 
) [inline]

A variant of vprintf_trunc that infers the destination buffer size.

Definition at line 687 of file SafeCString.hpp.

References vprintf_trunc().

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.

Always outputs a terminating '\0'.

RETURNS: the number of chars output, not including the terminating '\0'

Definition at line 676 of file SafeCString.hpp.

References BLOCXX_NAMESPACE::SafeCString::Impl::nchars_output().

Referenced by vprintf_trunc().


Variable Documentation

Definition at line 161 of file SafeCString.hpp.

Error codes for use with OverflowException class.

Definition at line 160 of file SafeCString.hpp.

Referenced by fgets_check(), BLOCXX_NAMESPACE::SafeCString::Impl::nchars_check(), and strcpy_check().