I would like to convert malloc() to calloc(). I am confused about using calloc() in this example because it takes 2 arguments while malloc() only one. So it's correct with mine:
(byteBuffer)calloc(sizeof(byteBufferStruct), len + 1));
The example:
typedef struct byte_buf {
size_t len;
uint8_t *bytes;
} byteBufferStruct, *byteBuffer;
byteBuffer mallocByteBuffer(size_t len)
{
byteBuffer retval;
if((retval = (byteBuffer) malloc(sizeof(byteBufferStruct) + len + 1)) == NULL) return NULL;
retval->len = len;
retval->bytes = (uint8_t *) (retval + 1) ; /* just past the byteBuffer in malloc'ed space */
return retval;
}