-/* $OpenBSD: buf_str.c,v 1.7 2014/04/17 14:28:44 beck Exp $ */
+/* $OpenBSD: buf_str.c,v 1.8 2014/04/26 13:07:16 jsing Exp $ */
/*
* Copyright (c) 2014 Bob Beck
*
BUF_strdup(const char *str)
{
char *ret = NULL;
+
if (str != NULL) {
if (!(ret = strdup(str)))
BUFerr(BUF_F_BUF_STRDUP, ERR_R_MALLOC_FAILURE);
BUF_strndup(const char *str, size_t siz)
{
char *ret = NULL;
+
if (str != NULL) {
if (!(ret = strndup(str, siz)))
BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE);
BUF_memdup(const void *data, size_t siz)
{
void *ret = NULL;
+
if (data != NULL) {
if (!(ret = malloc(siz)))
BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE);
return;
if (a->data != NULL) {
- memset(a->data, 0,(unsigned int)a->max);
+ memset(a->data, 0, (unsigned int)a->max);
free(a->data);
}
free(a);
return (len);
}
if (str->max >= len) {
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return (len);
}
} else {
str->data = ret;
str->max = n;
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return (len);
size_t n;
if (str->length >= len) {
- memset(&str->data[len], 0,str->length - len);
+ memset(&str->data[len], 0, str->length - len);
str->length = len;
return (len);
}
if (str->max >= len) {
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return (len);
}
BUF_reverse(unsigned char *out, const unsigned char *in, size_t size)
{
size_t i;
+
if (in) {
out += size - 1;
for (i = 0; i < size; i++)
-/* $OpenBSD: buf_str.c,v 1.7 2014/04/17 14:28:44 beck Exp $ */
+/* $OpenBSD: buf_str.c,v 1.8 2014/04/26 13:07:16 jsing Exp $ */
/*
* Copyright (c) 2014 Bob Beck
*
BUF_strdup(const char *str)
{
char *ret = NULL;
+
if (str != NULL) {
if (!(ret = strdup(str)))
BUFerr(BUF_F_BUF_STRDUP, ERR_R_MALLOC_FAILURE);
BUF_strndup(const char *str, size_t siz)
{
char *ret = NULL;
+
if (str != NULL) {
if (!(ret = strndup(str, siz)))
BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE);
BUF_memdup(const void *data, size_t siz)
{
void *ret = NULL;
+
if (data != NULL) {
if (!(ret = malloc(siz)))
BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE);
return;
if (a->data != NULL) {
- memset(a->data, 0,(unsigned int)a->max);
+ memset(a->data, 0, (unsigned int)a->max);
free(a->data);
}
free(a);
return (len);
}
if (str->max >= len) {
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return (len);
}
} else {
str->data = ret;
str->max = n;
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return (len);
size_t n;
if (str->length >= len) {
- memset(&str->data[len], 0,str->length - len);
+ memset(&str->data[len], 0, str->length - len);
str->length = len;
return (len);
}
if (str->max >= len) {
- memset(&str->data[str->length], 0,len - str->length);
+ memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return (len);
}
BUF_reverse(unsigned char *out, const unsigned char *in, size_t size)
{
size_t i;
+
if (in) {
out += size - 1;
for (i = 0; i < size; i++)