X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=buffer.c;h=bfa0dd82b9e74c3202bae2053a6b76462fbc100b;hp=8ca84c37214116daf50522e40d2cbbe2627f9fa4;hb=9e6ab0152703ad301042ce8810859f41fbee405a;hpb=355d6c883e8aafb8f424c22aa576cf8262ed9e58 diff --git a/buffer.c b/buffer.c index 8ca84c3..bfa0dd8 100644 --- a/buffer.c +++ b/buffer.c @@ -14,9 +14,10 @@ #include #include +#include + #include "buffer.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/debug.h" @@ -27,15 +28,15 @@ * Disregards the 'destroy' flag, which seems reserved for caller. * This is bad, but there's no apparent protocol for it. */ -BUFFER *mutt_buffer_init (BUFFER * b) +BUFFER *mutt_buffer_init(BUFFER *b) { if (!b) { - b = mem_malloc (sizeof (BUFFER)); + b = p_new(BUFFER, 1); if (!b) return NULL; } else { - mem_free(&b->data); + p_delete(&b->data); } memset (b, 0, sizeof (BUFFER)); return b; @@ -49,7 +50,7 @@ BUFFER *mutt_buffer_init (BUFFER * b) * Disregards the 'destroy' flag, which seems reserved for caller. * This is bad, but there's no apparent protocol for it. */ -BUFFER *mutt_buffer_from (BUFFER * b, char *seed) +BUFFER *mutt_buffer_from (BUFFER * b, const char *seed) { if (!seed) return NULL; @@ -76,22 +77,22 @@ void mutt_buffer_free (BUFFER ** p) if (!p || !*p) return; - mem_free (&(*p)->data); + p_delete(&(*p)->data); /* dptr is just an offset to data and shouldn't be freed */ - mem_free (p); + p_delete(p); } /* dynamically grows a BUFFER to accomodate s, in increments of 128 bytes. * Always one byte bigger than necessary for the null terminator, and * the buffer is always null-terminated */ -void mutt_buffer_add (BUFFER * buf, const char *s, size_t len) +void mutt_buffer_add (BUFFER *buf, const char *s, size_t len) { size_t offset; if (buf->dptr + len + 1 > buf->data + buf->dsize) { offset = buf->dptr - buf->data; buf->dsize += len < 128 ? 128 : len + 1; - mem_realloc ((void **) &buf->data, buf->dsize); + p_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + offset; } memcpy (buf->dptr, s, len); @@ -204,10 +205,10 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) cmd = str_substrdup (tok->dptr, pc); if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) { debug_print (1, ("unable to fork command: %s\n", cmd)); - mem_free (&cmd); + p_delete(&cmd); return (-1); } - mem_free (&cmd); + p_delete(&cmd); tok->dptr = pc + 1; @@ -223,21 +224,21 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) * the token */ if (expn.data && qc) { mutt_buffer_addstr (dest, expn.data); - mem_free (&expn.data); + p_delete(&expn.data); } else if (expn.data) { expnlen = str_len (expn.data); tok->dsize = expnlen + str_len (tok->dptr) + 1; - ptr = mem_malloc (tok->dsize); + ptr = xmalloc(tok->dsize); memcpy (ptr, expn.data, expnlen); strcpy (ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */ if (tok->destroy) - mem_free (&tok->data); + p_delete(&tok->data); tok->data = ptr; tok->dptr = ptr; tok->destroy = 1; /* mark that the caller should destroy this data */ ptr = NULL; - mem_free (&expn.data); + p_delete(&expn.data); } } else if (ch == '$' && (!qc || qc == '"') @@ -263,7 +264,7 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) (mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp))) mutt_buffer_addstr (dest, env); } - mem_free (&var); + p_delete(&var); } else mutt_buffer_addch (dest, ch);