*/
static bool create_hcache_dir(const char *path)
{
- if (!path)
+ char *dir = mutt_str_strdup(path);
+ if (!dir)
return false;
- static char dir[PATH_MAX];
- mutt_str_strfcpy(dir, path, sizeof(dir));
-
char *p = strrchr(dir, '/');
if (!p)
+ {
+ FREE(&dir);
return true;
+ }
*p = '\0';
- if (mutt_file_mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
- return true;
- mutt_error(_("Can't create %s: %s"), dir, strerror(errno));
- return false;
+ int rc = mutt_file_mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (rc != 0)
+ mutt_error(_("Can't create %s: %s"), dir, strerror(errno));
+
+ FREE(&dir);
+ return (rc == 0);
}
/**
*/
void *mutt_hcache_fetch_raw(header_cache_t *hc, const char *key, size_t keylen)
{
- char path[PATH_MAX];
const struct HcacheOps *ops = hcache_get_ops();
if (!hc || !ops)
return NULL;
- keylen = snprintf(path, sizeof(path), "%s%s", hc->folder, key);
+ struct Buffer path = mutt_buffer_make(1024);
+
+ keylen = mutt_buffer_printf(&path, "%s%s", hc->folder, key);
- return ops->fetch(hc->ctx, path, keylen);
+ void *blob = ops->fetch(hc->ctx, mutt_b2s(&path), keylen);
+ mutt_buffer_dealloc(&path);
+ return blob;
}
/**
int mutt_hcache_store_raw(header_cache_t *hc, const char *key, size_t keylen,
void *data, size_t dlen)
{
- char path[PATH_MAX];
const struct HcacheOps *ops = hcache_get_ops();
if (!hc || !ops)
return -1;
- keylen = snprintf(path, sizeof(path), "%s%s", hc->folder, key);
+ struct Buffer path = mutt_buffer_make(1024);
- return ops->store(hc->ctx, path, keylen, data, dlen);
+ keylen = mutt_buffer_printf(&path, "%s%s", hc->folder, key);
+
+ int rc = ops->store(hc->ctx, mutt_b2s(&path), keylen, data, dlen);
+ mutt_buffer_dealloc(&path);
+ return rc;
}
/**
*/
int mutt_hcache_delete_header(header_cache_t *hc, const char *key, size_t keylen)
{
- char path[PATH_MAX];
const struct HcacheOps *ops = hcache_get_ops();
-
if (!hc)
return -1;
- keylen = snprintf(path, sizeof(path), "%s%s", hc->folder, key);
+ struct Buffer path = mutt_buffer_make(1024);
- return ops->delete_header(hc->ctx, path, keylen);
+ keylen = mutt_buffer_printf(&path, "%s%s", hc->folder, key);
+
+ int rc = ops->delete_header(hc->ctx, mutt_b2s(&path), keylen);
+ mutt_buffer_dealloc(&path);
+ return rc;
}
/**
*/
static void *hcache_kyotocabinet_open(const char *path)
{
- char kcdbpath[PATH_MAX];
- int printfresult;
-
- printfresult = snprintf(kcdbpath, sizeof(kcdbpath), "%s#type=kct#opts=%s#rcomp=lex",
- path, C_HeaderCacheCompress ? "lc" : "l");
- if ((printfresult < 0) || (printfresult >= sizeof(kcdbpath)))
- {
- return NULL;
- }
-
KCDB *db = kcdbnew();
if (!db)
return NULL;
- if (kcdbopen(db, kcdbpath, KCOWRITER | KCOCREATE))
- return db;
- else
+ struct Buffer kcdbpath = mutt_buffer_make(1024);
+
+ mutt_buffer_printf(&kcdbpath, "%s#type=kct#opts=%s#rcomp=lex", path,
+ C_HeaderCacheCompress ? "lc" : "l");
+
+ if (!kcdbopen(db, mutt_b2s(&kcdbpath), KCOWRITER | KCOCREATE))
{
int ecode = kcdbecode(db);
- mutt_debug(LL_DEBUG2, "kcdbopen failed for %s: %s (ecode %d)\n", kcdbpath,
- kcdbemsg(db), ecode);
+ mutt_debug(LL_DEBUG2, "kcdbopen failed for %s: %s (ecode %d)\n",
+ mutt_b2s(&kcdbpath), kcdbemsg(db), ecode);
kcdbdel(db);
- return NULL;
+ db = NULL;
}
+
+ mutt_buffer_dealloc(&kcdbpath);
+ return db;
}
/**