X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Ftags.c;h=0d7a27f141b5062997214a741c44ed2c00c81170;hb=767693caf2b41c2e857688d10d2c71bc77c0bbad;hp=5ec12fa1ed9a35e65aaee29924e48b42f65935e8;hpb=dead5bdc521b34c85256737b616f4072a78dc2fb;p=blerg.git diff --git a/database/tags.c b/database/tags.c index 5ec12fa..0d7a27f 100644 --- a/database/tags.c +++ b/database/tags.c @@ -62,7 +62,7 @@ tag_scan_start: int tag_add(const char *author, const char *tag, uint64_t record) { char filename[512]; - struct tag t; + struct blergref t; memset(t.author, 0, 32); strncpy(t.author, author, 32); @@ -86,8 +86,8 @@ int tag_add(const char *author, const char *tag, uint64_t record) { perror("Could not open tag file"); return 0; } - int n = write(tag_fd, &t, sizeof(struct tag)); - if (n < sizeof(struct tag)) { + int n = write(tag_fd, &t, sizeof(struct blergref)); + if (n < sizeof(struct blergref)) { perror("Could not write new tag"); return 0; } @@ -97,15 +97,20 @@ int tag_add(const char *author, const char *tag, uint64_t record) { return 1; } -struct tag * tag_list(const char *tag, uint64_t offset, int *count, int direction) { +struct blergref * tag_list(const char *tag, uint64_t offset, int *count, int direction) { char filename[512]; struct stat st; - struct tag *taglist; - struct tag *retlist; + struct blergref *taglist; + struct blergref *retlist; uint64_t n_tag_records; if (!valid_tag_name(tag + 1)) return NULL; + + if (!(direction == 1 || direction == -1)) { + fprintf(stderr, "Invalid direction: %d\n", direction); + return NULL; + } switch(tag[0]) { case '#': @@ -129,7 +134,7 @@ struct tag * tag_list(const char *tag, uint64_t offset, int *count, int directio if (st.st_size == 0) { goto tag_list_map_failed; } - n_tag_records = st.st_size / sizeof(struct tag); + n_tag_records = st.st_size / sizeof(struct blergref); if (*count > n_tag_records - offset) *count = n_tag_records - offset; if (offset > n_tag_records) { @@ -137,22 +142,22 @@ struct tag * tag_list(const char *tag, uint64_t offset, int *count, int directio goto tag_list_map_failed; } - taglist = (struct tag *) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, tag_fd, 0); + taglist = (struct blergref *) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, tag_fd, 0); if (taglist == MAP_FAILED) { perror("Could not mmap tag file"); goto tag_list_map_failed; } - retlist = (struct tag *) malloc(sizeof(struct tag) * *count); + retlist = (struct blergref *) malloc(sizeof(struct blergref) * *count); if (retlist == NULL) { perror("Could not allocate memory for tag list"); goto tag_list_malloc_failed; } switch(direction) { case 1: - memcpy(retlist, taglist + offset, sizeof(struct tag) * *count); + memcpy(retlist, taglist + offset, sizeof(struct blergref) * *count); break; case -1: - memcpy(retlist, taglist + (n_tag_records - *count - offset), sizeof(struct tag) * *count); + memcpy(retlist, taglist + (n_tag_records - *count - offset), sizeof(struct blergref) * *count); break; }