X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=hcache.c;h=953e70f1e226aa175cce07bd04f5d8fc99cfa40d;hp=532a2b8d52343708528d18b49293dde65ab3ed73;hb=32962d1bbc4260395f7afa183e980a4d4dc3f990;hpb=23e6291cb5d5b4cd2008403d8b628007fd75ff23 diff --git a/hcache.c b/hcache.c index 532a2b8..953e70f 100644 --- a/hcache.c +++ b/hcache.c @@ -8,22 +8,13 @@ * It's licensed under the GNU General Public License, * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ + +#include #ifdef USE_HCACHE #define MUTTNG_HCACHE_ID "0x004" -# ifdef HAVE_INTTYPES_H -# include -# else -# ifdef HAVE_STDINT_H -# include -# endif -# endif - #if defined(HAVE_QDBM) #include #include @@ -34,15 +25,7 @@ #include #endif -#include -#include -#ifdef HAVE_SYS_TIME_H -#include -#endif - -#include #include - #include #include "charset.h" @@ -74,24 +57,16 @@ typedef union { unsigned long uid_validity; } validate; -static void *lazy_malloc (ssize_t siz) -{ - if (0 < siz && siz < 4096) { - siz = 4096; - } +#define UPPER4K(i) ((i & ~(4096 - 1)) + 4096) - return xmalloc(siz); +static unsigned char *lazy_malloc(ssize_t siz) +{ + return p_new(unsigned char, UPPER4K(siz)); } -static void lazy_realloc(void *ptr, ssize_t siz) +static void lazy_realloc(unsigned char **p, ssize_t siz) { - char **p = ptr; - - if (p != NULL && 0 < siz && siz < 4096) { - return; - } - - p_realloc(&p, siz); + p_realloc(p, UPPER4K(siz)); } static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off) @@ -128,25 +103,6 @@ static unsigned char *dump_char (char *c, unsigned char *d, int *off) return d; } -#if 0 -static unsigned char *dump_char_size (char *c, unsigned char *d, int *off, - ssize_t size) -{ - if (c == NULL) { - size = 0; - d = dump_int (size, d, off); - return d; - } - - d = dump_int (size, d, off); - lazy_realloc (&d, *off + size); - memcpy (d + *off, c, size); - *off += size; - - return d; -} -#endif - static void restore_char (char **c, const unsigned char *d, int *off) { unsigned int size; @@ -234,46 +190,7 @@ static void restore_list (string_list_t ** l, const unsigned char *d, int *off) *l = NULL; } -#if 0 -static unsigned char *dump_buffer (BUFFER * b, unsigned char *d, int *off) -{ - if (!b) { - d = dump_int (0, d, off); - return d; - } - else { - d = dump_int (1, d, off); - } - - d = dump_char_size (b->data, d, off, b->dsize + 1); - d = dump_int (b->dptr - b->data, d, off); - d = dump_int (b->dsize, d, off); - d = dump_int (b->destroy, d, off); - - return d; -} - -static void restore_buffer (BUFFER ** b, const unsigned char *d, int *off) -{ - unsigned int used; - unsigned int offset; - - restore_int (&used, d, off); - if (!used) { - return; - } - - *b = p_new(BUFFER, 1); - - restore_char (&(*b)->data, d, off); - restore_int (&offset, d, off); - (*b)->dptr = (*b)->data + offset; - restore_int (&(*b)->dsize, d, off); - restore_int ((unsigned int *) &(*b)->destroy, d, off); -} -#endif - -static unsigned char *dump_parameter (PARAMETER * p, unsigned char *d, +static unsigned char *dump_parameter (parameter_t * p, unsigned char *d, int *off) { unsigned int counter = 0; @@ -294,21 +211,19 @@ static unsigned char *dump_parameter (PARAMETER * p, unsigned char *d, } static void -restore_parameter (PARAMETER ** p, const unsigned char *d, int *off) +restore_parameter (parameter_t ** p, const unsigned char *d, int *off) { unsigned int counter; restore_int (&counter, d, off); while (counter) { - *p = p_new(PARAMETER, 1); + *p = parameter_new(); restore_char (&(*p)->attribute, d, off); restore_char (&(*p)->value, d, off); p = &(*p)->next; counter--; } - - *p = NULL; } static unsigned char *dump_body (BODY * c, unsigned char *d, int *off) @@ -571,7 +486,7 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) h->env = envelope_new(); restore_envelope (h->env, d, &off); - h->content = mutt_new_body (); + h->content = body_new(); restore_body (h->content, d, &off); restore_char (&h->maildir_flags, d, &off);