#include "plugin.h"
-#include "utils_avltree.h"
+#include "utils/avltree/avltree.h"
#include "utils_fbhash.h"
struct fbhash_s {
fh = fopen(h->filename, "r");
if (fh == NULL)
- return (-1);
+ return -1;
fl.l_type = F_RDLCK;
fl.l_whence = SEEK_SET;
status = fcntl(fileno(fh), F_SETLK, &fl);
if (status != 0) {
fclose(fh);
- return (-1);
+ return -1;
}
tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (tree == NULL) {
fclose(fh);
- return (-1);
+ return -1;
}
/* Read `fh' into `tree' */
char *key_copy;
char *value_copy;
- buffer[sizeof(buffer) - 1] = 0;
+ buffer[sizeof(buffer) - 1] = '\0';
len = strlen(buffer);
/* Remove trailing newline characters. */
fbh_free_tree(h->tree);
h->tree = tree;
- return (0);
+ return 0;
} /* }}} int fbh_read_file */
static int fbh_check_file(fbhash_t *h) /* {{{ */
status = stat(h->filename, &statbuf);
if (status != 0)
- return (-1);
+ return -1;
if (h->mtime >= statbuf.st_mtime)
- return (0);
+ return 0;
status = fbh_read_file(h);
if (status == 0)
h->mtime = statbuf.st_mtime;
- return (status);
+ return status;
} /* }}} int fbh_check_file */
/*
int status;
if (file == NULL)
- return (NULL);
+ return NULL;
h = calloc(1, sizeof(*h));
if (h == NULL)
- return (NULL);
+ return NULL;
h->filename = strdup(file);
if (h->filename == NULL) {
free(h);
- return (NULL);
+ return NULL;
}
h->mtime = 0;
if (status != 0) {
fbh_destroy(h);
free(h);
- return (NULL);
+ return NULL;
}
- return (h);
+ return h;
} /* }}} fbhash_t *fbh_create */
void fbh_destroy(fbhash_t *h) /* {{{ */
int status;
if ((h == NULL) || (key == NULL))
- return (NULL);
+ return NULL;
value = NULL;
value_copy = NULL;
pthread_mutex_unlock(&h->lock);
- return (value_copy);
+ return value_copy;
} /* }}} char *fbh_get */