Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void *buffer_alloc(void *buf, char *str) {
- void *tmp = NULL;
- if (buf == NULL) {
- tmp = (char*)calloc(strlen(str) + 1, sizeof(*buf));
- if (tmp == NULL) {
- printf("calloc(): failed. Memory full ?\n");
- return ;
- }
- strncat(tmp, str, strlen(str) + 1);
- } else {
- if (print_debug() == true) printf("buffer_alloc: realloc\n");
- if ((tmp = (char *)realloc(buf, strlen(buf) + strlen(str) + 1)) == NULL) {
- printf("realloc(): failed. Memory full ?\n");
- return ;
- } else {
- strncat(tmp, str, strlen(str) + 1);
- }
- }
- buf = tmp;
- return buf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement