projects
/
blerg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update to Enyo and Onyx 2.0-beta4
[blerg.git]
/
database
/
tags.c
diff --git
a/database/tags.c
b/database/tags.c
index
51d8698
..
dc6bac8
100644
(file)
--- 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];
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);
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;
}
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;
}
perror("Could not write new tag");
return 0;
}
@@
-97,14
+97,14
@@
int tag_add(const char *author, const char *tag, uint64_t record) {
return 1;
}
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;
char filename[512];
struct stat st;
- struct
tag
*taglist;
- struct
tag
*retlist;
+ struct
blergref
*taglist;
+ struct
blergref
*retlist;
uint64_t n_tag_records;
uint64_t n_tag_records;
- if (!valid_name(tag + 1))
+ if (!valid_
tag_
name(tag + 1))
return NULL;
switch(tag[0]) {
return NULL;
switch(tag[0]) {
@@
-122,40
+122,37
@@
struct tag * tag_list(const char *tag, uint64_t offset, int *count, int directio
int tag_fd = open(filename, O_RDONLY, 0600);
if (tag_fd == -1) {
perror("Could not open tag file");
int tag_fd = open(filename, O_RDONLY, 0600);
if (tag_fd == -1) {
perror("Could not open tag file");
- *count = 0;
- return NULL;
+ goto tag_list_open_failed;
}
fstat(tag_fd, &st);
if (st.st_size == 0) {
}
fstat(tag_fd, &st);
if (st.st_size == 0) {
- close(tag_fd);
- *count = 0;
- return NULL;
+ goto tag_list_map_failed;
}
}
- n_tag_records = st.st_size / sizeof(struct
tag
);
- if (*count > n_tag_records)
- *count = n_tag_records;
+ 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) {
fprintf(stderr, "Cannot access tag record beyond end\n");
if (offset > n_tag_records) {
fprintf(stderr, "Cannot access tag record beyond end\n");
-
return NULL
;
+
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;
}
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:
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:
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;
}
break;
}
@@
-168,13
+165,14
@@
tag_list_malloc_failed:
tag_list_map_failed:
close(tag_fd);
tag_list_open_failed:
tag_list_map_failed:
close(tag_fd);
tag_list_open_failed:
+ *count = 0;
return NULL;
}
int tag_exists(const char *tag) {
char filename[512];
return NULL;
}
int tag_exists(const char *tag) {
char filename[512];
- if (!valid_name(tag + 1))
+ if (!valid_
tag_
name(tag + 1))
return 0;
if (!(tag[0] == '@' || tag[0] == '#')) {
return 0;
if (!(tag[0] == '@' || tag[0] == '#')) {