X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=hcache.c;h=da3d6bbc08b9b7b3198c9ebac9619b3bafae088f;hp=496fd09074f2a5574d5a006adba097352421e486;hb=01bd0a7410e476abaebf03d820bcf31a5ec4c7c0;hpb=9eb3b25249e78d778b6d0583b06a7c5615709e63 diff --git a/hcache.c b/hcache.c index 496fd09..da3d6bb 100644 --- a/hcache.c +++ b/hcache.c @@ -41,17 +41,18 @@ #endif #include +#include #include -#include #include +#include "charset.h" #include "mutt.h" #include #include "mx.h" #include "lib.h" -static struct header_cache { +struct header_cache { #if defined(HAVE_QDBM) VILLA *db; char *folder; @@ -67,31 +68,23 @@ static struct header_cache { int fd; char lockfile[_POSIX_PATH_MAX]; #endif -} HEADER_CACHE; +}; typedef union { struct timeval timeval; 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 +121,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,45 +208,6 @@ 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, int *off) { @@ -301,14 +236,12 @@ restore_parameter (PARAMETER ** p, const unsigned char *d, int *off) 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) @@ -857,7 +790,7 @@ void *mutt_hcache_open (const char *path, const char *folder) struct stat sb; u_int32_t createflags = DB_CREATE; int ret; - struct header_cache *h = calloc (1, sizeof (HEADER_CACHE)); + struct header_cache *h = p_new(struct header_cache, 1); int pagesize = atoi (HeaderCachePageSize);