* Daniel Silverstone <dsilvers@digital-scurf.org>
*
* Copyright 2004 Daniel Silverstone and Project Purple
- *
- * $Id: keydb_fs.c,v 1.2 2004/05/28 02:55:49 noodles Exp $
*/
#include <sys/types.h>
{
register uint32_t h = FNV_offset_basis;
register uint32_t p = FNV_mixing_prime;
- register uint32_t n = strlen(ptr);
+ register uint32_t n = strlen((char *) ptr);
register uint8_t *c = ptr;
while (n--) {
h *= p;
void keypath(char *buffer, uint64_t _keyid)
{
uint64_t keyid = _keyid << 32;
- snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX/%016llX",
+ snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X/%016llX",
config.db_dir, (uint8_t) ((keyid >> 56) & 0xFF),
(uint8_t) ((keyid >> 48) & 0xFF),
(uint32_t) (keyid >> 32), _keyid);
void keydir(char *buffer, uint64_t _keyid)
{
uint64_t keyid = _keyid << 32;
- snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX", config.db_dir,
+ snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X", config.db_dir,
(uint8_t) ((keyid >> 56) & 0xFF),
(uint8_t) ((keyid >> 48) & 0xFF),
(uint32_t) (keyid >> 32));
(uint8_t) ((keyid >> 16) & 0xFF));
mkdir(buffer, 0777);
- snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08lX", config.db_dir, what,
+ snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08X", config.db_dir, what,
(uint8_t) ((keyid >> 24) & 0xFF),
(uint8_t) ((keyid >> 16) & 0xFF), (uint32_t) (keyid));
mkdir(buffer, 0777);
void wordpath(char *buffer, char *word, uint32_t hash, uint64_t keyid)
{
- snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s/%016llX",
+ snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s/%016llX",
config.db_dir, (uint8_t) ((hash >> 24) & 0xFF),
(uint8_t) ((hash >> 16) & 0xFF), hash, word, keyid);
}
void worddir(char *buffer, char *word, uint32_t hash)
{
- snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s", config.db_dir,
+ snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s", config.db_dir,
(uint8_t) ((hash >> 24) & 0xFF),
(uint8_t) ((hash >> 16) & 0xFF), hash, word);
}
wl = wl->next;
}
- llfree(wordlist, NULL);
+ llfree(wordlist, free);
}
if (!intrans)
de = readdir(d);
if (de && de->d_name[0] != '.') {
if ((!mct)
- || (llfind(mct, de->d_name, strcmp) !=
+ || (llfind(mct, de->d_name,
+ (int (*)(const void *, const void *))
+ strcmp) !=
NULL)) {
logthing(LOGTHING_CRITICAL,
"Found %s // %s", word,
{
struct ll *wordlist = NULL, *wl = NULL;
struct ll *keylist = NULL;
+ char *searchtext = NULL;
int addedkeys = 0;
logthing(LOGTHING_CRITICAL, "Search was '%s'", search);
- wl = wordlist = makewordlist(wordlist, search);
+ searchtext = strdup(search);
+ wl = wordlist = makewordlist(wordlist, searchtext);
keylist = internal_get_key_by_word(wordlist->object, NULL);
if (!keylist) {
llfree(wordlist, NULL);
+ free(searchtext);
+ searchtext = NULL;
return 0;
}
if (!nkl) {
llfree(wordlist, NULL);
llfree(keylist, free);
+ free(searchtext);
+ searchtext = NULL;
return 0;
}
llfree(keylist, free);
}
llfree(keylist, free);
+ free(searchtext);
+ searchtext = NULL;
return addedkeys;
}
keydir(buffer, keyid);
d = opendir(buffer);
- do {
- de = readdir(d);
- if (de)
- if (de && de->d_name[0] != '.') {
- ret = strtoull(de->d_name, NULL, 16);
- }
- } while (de && de->d_name[0] == '.');
- closedir(d);
+ if (d) {
+ do {
+ de = readdir(d);
+ if (de)
+ if (de && de->d_name[0] != '.') {
+ ret = strtoull(de->d_name, NULL, 16);
+ }
+ } while (de && de->d_name[0] == '.');
+ closedir(d);
+ }
return ret;
}