Cleanup unused vars and filename lengths
[blerg.git] / database / database.c
index 033875b..e0c9eb7 100644 (file)
@@ -80,7 +80,7 @@ int blerg_remap_data(struct blerg *blerg) {
 }
 
 int blerg_segment_switch(struct blerg *blerg, int new_segment) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        uint64_t max_sequence_no = blerg_get_record_count(blerg);
        struct stat st;
 
@@ -100,7 +100,7 @@ int blerg_segment_switch(struct blerg *blerg, int new_segment) {
        blerg_segment_close(blerg);
 
        /* Load and map the index */
-       snprintf(filename, 512, "%s/index%d", blerg->base_path, new_segment);
+       snprintf(filename, FILENAME_MAX, "%s/index%d", blerg->base_path, new_segment);
        blerg->index_fd = open(filename, O_RDWR | O_CREAT, 0600);
        if (blerg->index_fd == -1) {
                perror("Could not open index");
@@ -123,7 +123,7 @@ int blerg_segment_switch(struct blerg *blerg, int new_segment) {
        }
 
        /* Load data file */
-       sprintf(filename, "%s/data%d", blerg->base_path, new_segment);
+       snprintf(filename, FILENAME_MAX, "%s/data%d", blerg->base_path, new_segment);
        blerg->data_fd = open(filename, O_RDWR | O_APPEND | O_CREAT, 0600);
        if (blerg->data_fd == -1) {
                perror("Could not open data");
@@ -149,15 +149,14 @@ open_failed_index_open:
 }
 
 int blerg_exists(const char *name) {
-       int namelen = strlen(name);
-       char filename[512];
+       char filename[FILENAME_MAX];
 
        if (!valid_name(name)) {
                fprintf(stderr, "Invalid name\n");
                return 0;
        }
 
-       snprintf(filename, 512, "%s/%s", blergconf.data_path, name);
+       snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.data_path, name);
        if (access(filename, F_OK) == -1)
                return 0;
        else
@@ -166,7 +165,7 @@ int blerg_exists(const char *name) {
 
 struct blerg *blerg_open(const char *name) {
        int namelen = strlen(name);
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stat st;
        uint64_t sequence;
 
@@ -187,13 +186,13 @@ struct blerg *blerg_open(const char *name) {
        blerg->data = NULL;
 
        /* Make the directory if it doesn't exist */
-       blerg->base_path = malloc(512);
-       snprintf(blerg->base_path, 512, "%s/%s", blergconf.data_path, name);
+       blerg->base_path = malloc(FILENAME_MAX);
+       snprintf(blerg->base_path, FILENAME_MAX, "%s/%s", blergconf.data_path, name);
        if (access(blerg->base_path, F_OK) == -1)
                mkdir(blerg->base_path, 0755);
 
        /* Open and map metadata */
-       snprintf(filename, 512, "%s/meta", blerg->base_path);
+       snprintf(filename, FILENAME_MAX, "%s/meta", blerg->base_path);
        blerg->meta_fd = open(filename, O_RDWR | O_CREAT, 0600);
        if (blerg->meta_fd == -1) {
                perror("Could not open metadata");