38#include "blocxx/BLOCXX_config.h"
43using namespace blocxx;
44using namespace blocxx::SafeCString;
48 inline char const * strend(
char const * s, std::size_t n)
50 return static_cast<char const *
>(std::memchr(s,
'\0', n));
53 inline char * strend(
char * s, std::size_t n)
55 return const_cast<char *
>(strend(
static_cast<char const *
>(s), n));
58 char * strend_checked(
char * s, std::size_t n)
60 char * retval = strend(s, n);
69 "cstring catenation first operand unterminated",
78 inline char * safe_strcpy(
char * dst,
char const * src, std::size_t n)
80#ifdef BLOCXX_HAS_MEMCCPY
81 char * rv =
static_cast<char *
>(std::memccpy(dst, src,
'\0', n));
82 return rv ? rv - 1 : 0;
84 char const * end = strend(src, n);
87 size_t len = end - src;
88 std::memcpy(dst, src, len + 1);
93 std::memcpy(dst, src, n);
109 char *
retval =
new char[std::strlen(s) + 1];
110 return std::strcpy(
retval, s);
115 char *
retval =
new (std::nothrow)
char[std::strlen(s)];
221 return static_cast<std::size_t
>(
retval);
#define BLOCXX_DEFINE_EXCEPTION(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
#define BLOCXX_THROW_ERR(exType, msg, err)
Throw an exception using FILE and LINE.
std::size_t nchars_check(int retval, std::size_t dstsize)
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 allocat...
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,...
char * str_dup(char const *s)
Like std::strdup, except that new is used to allocate memory.
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 appe...
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),...
int const RESULT_TRUNCATED
Error codes for use with OverflowException class.
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),...
bool operator==(const Array< T > &x, const Array< T > &y)