Added max id for unix_fs_driver + better macros

This commit is contained in:
2023-07-02 12:55:42 +03:00
parent d5f0e478e1
commit 3d798c88bf
3 changed files with 62 additions and 10 deletions

View File

@@ -53,12 +53,20 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
UnixFsDriverData driver_data = { path };
int max_id = unix_fs_driver_get_max_id(&driver_data);
if (max_id <= 0) {
fprintf(stderr, "Warning: failed to get id of last comment\n");
} else if (id >= max_id) {
fprintf(stderr, "Last comment has id %d, which is less than %d\n", max_id - 1, id);
exit(EXIT_FAILURE);
}
CommentHeader *header = malloc(sizeof(CommentHeader));
header->user_sid = malloc(BUF_SZ);
header->user_displayname = malloc(BUF_SZ);
UnixFsDriverData driver_data = { path };
if (driver->get_header(&driver_data, header, id) < 0) {
fprintf(stderr, "failed to get header of comment, are you sure it exists?\n");
exit(EXIT_FAILURE);