char *
ss_string_get(const ss_string_t *str,
size_t bufsize, /* Size of BUF (only referenced if BUF is non-null). */
char *buf /* Optional buffer in which to store the C string. This buffer is assumed to be an
* array of at least BUFSIZE characters. */
)
{
SS_ENTER(ss_string_get, charP);
char *tmp=NULL;
if (!str) SS_ERROR_FMT(USAGE, ("no ss_string_t supplied"));
if (buf) {
if (bufsize<str->nbytes) SS_ERROR_FMT(OVERFLOW, ("supplied buffer is too short"));
} else {
tmp = buf = malloc(MAX(1,str->nbytes));
if (!tmp) SS_ERROR(RESOURCE);
if (0==str->nbytes) tmp[0] = '\0';
}
memcpy(buf, str->p, str->nbytes);
SS_CLEANUP:
SS_FREE(tmp);
SS_LEAVE(buf);
}