X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Fdatabase.c;h=cb5cf0c58b43a7c5465fc2d2ad20017aef032f94;hb=b6235374b91ba7acf62c06c72de2f1291f46ac4c;hp=1e33811c1d29f13f638ff603fa2481f32f3c5a29;hpb=1cf0f1ebfbd5b5a621af2a49ac0328fd0cec4bf4;p=blerg.git diff --git a/database/database.c b/database/database.c index 1e33811..cb5cf0c 100644 --- a/database/database.c +++ b/database/database.c @@ -1,3 +1,6 @@ +/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a + * BSD-style license. Please see the COPYING file for details. + */ #include #include #include @@ -10,6 +13,7 @@ #include #include #include "database.h" +#include "util.h" #include "config.h" uint64_t blerg_get_record_count(struct blerg *blerg) { @@ -111,8 +115,8 @@ int blerg_exists(const char *name) { int namelen = strlen(name); char filename[512]; - if (namelen > 32) { - perror("Name too long"); + if (!valid_name(name)) { + fprintf(stderr, "Invalid name\n"); return 0; } @@ -129,8 +133,8 @@ struct blerg *blerg_open(const char *name) { struct stat st; uint64_t sequence; - if (namelen > 32) { - perror("Name too long"); + if (!valid_name(name)) { + fprintf(stderr, "Invalid name\n"); return NULL; } struct blerg *blerg = malloc(sizeof(struct blerg)); @@ -203,7 +207,7 @@ int blerg_close(struct blerg *blerg) { int blerg_store(struct blerg *blerg, const char *data, int len) { if (len > MAX_RECORD_SIZE) { - printf("len > 64K\n"); + fprintf(stderr, "len > 64K\n"); return -1; } @@ -212,7 +216,7 @@ int blerg_store(struct blerg *blerg, const char *data, int len) { uint64_t record = blerg_increment_record_count(blerg); if (record == -1) { - printf("Could not find free record\n"); + fprintf(stderr, "Could not find free record\n"); return -1; } int segment = record / RECORDS_PER_SEGMENT; @@ -252,7 +256,7 @@ int blerg_store(struct blerg *blerg, const char *data, int len) { int blerg_fetch(struct blerg *blerg, int record, char **data, int *length) { if (record < 0) { - printf("Invalid record\n"); + fprintf(stderr, "Invalid record\n"); return 0; } @@ -262,7 +266,7 @@ int blerg_fetch(struct blerg *blerg, int record, char **data, int *length) { int seg_rec = record % RECORDS_PER_SEGMENT; if ((blerg->index[seg_rec].flags & 0x1) == 0) { - printf("Invalid record\n"); + fprintf(stderr, "Invalid record\n"); return 0; } @@ -275,7 +279,7 @@ int blerg_fetch(struct blerg *blerg, int record, char **data, int *length) { fstat(blerg->data_fd, &st); blerg->data_size = st.st_size; if (rec_offset > blerg->data_size) { - printf("Record offset outside of data!?"); + fprintf(stderr, "Record offset outside of data!?"); return 0; } @@ -302,7 +306,7 @@ int blerg_fetch(struct blerg *blerg, int record, char **data, int *length) { time_t blerg_get_timestamp(struct blerg *blerg, int record) { if (record < 0) { - printf("Invalid record\n"); + fprintf(stderr, "Invalid record\n"); return 0; } @@ -312,7 +316,7 @@ time_t blerg_get_timestamp(struct blerg *blerg, int record) { int seg_rec = record % RECORDS_PER_SEGMENT; if ((blerg->index[seg_rec].flags & 0x1) == 0) { - printf("Invalid record\n"); + fprintf(stderr, "Invalid record\n"); return 0; }