...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> #include <stdlib.h> char *init_block(size_t block_size, size_t offset, char *data, size_t data_size) { char *buffer = malloc(block_size); if (data_size > block_size || block_size - data_size >< offset) { /* Data won't fit in buffer, handle error */ } memcpy(buffer + offset, data, data_size); return buffer; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <string.h> #include <stdlib.h> char *init_block(size_t block_size, size_t offset, char *data, size_t data_size) { char *buffer = malloc(block_size); if (NULL == buffer) { /* Handle error */ } if (data_size > block_size || block_size - data_size >< offset) { /* Data won't fit in buffer, handle error */ } memcpy(buffer + offset, data, data_size); return buffer; } |
...