[Core] Allow switch_buffer_write() to fill in a buffer with zeros. Add switch_buffer_zero_fill()
This commit is contained in:
parent
f31dcd26f8
commit
aa161b9e58
|
@ -132,13 +132,15 @@ SWITCH_DECLARE(void) switch_buffer_set_loops(_In_ switch_buffer_t *buffer, _In_
|
|||
|
||||
/*! \brief Write data into a switch_buffer_t up to the length of datalen
|
||||
* \param buffer any buffer of type switch_buffer_t
|
||||
* \param data pointer to the data to be written
|
||||
* \param data pointer to the data to be written or 0 to fill in with datalen zeros
|
||||
* \param datalen amount of data to be written
|
||||
* \return int amount of buffer used after the write, or 0 if no space available
|
||||
*/
|
||||
SWITCH_DECLARE(switch_size_t) switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen)
|
||||
const void *data, _In_ switch_size_t datalen);
|
||||
|
||||
#define switch_buffer_zero_fill(_buffer, _datalen) switch_buffer_write(_buffer, 0, _datalen);
|
||||
|
||||
/*! \brief Remove data from the buffer
|
||||
* \param buffer any buffer of type switch_buffer_t
|
||||
* \param datalen amount of data to be removed
|
||||
|
|
|
@ -344,7 +344,12 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const
|
|||
return 0;
|
||||
}
|
||||
|
||||
memcpy(buffer->head + buffer->used, data, datalen);
|
||||
if (data) {
|
||||
memcpy(buffer->head + buffer->used, data, datalen);
|
||||
} else {
|
||||
memset(buffer->head + buffer->used, 0, datalen);
|
||||
}
|
||||
|
||||
buffer->used += datalen;
|
||||
buffer->actually_used += datalen;
|
||||
return buffer->used;
|
||||
|
|
Loading…
Reference in New Issue