diff options
author | Robby Zambito <contact@robbyzambito.me> | 2021-09-29 21:11:17 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2021-09-29 21:11:17 -0400 |
commit | b780db3979f269549cd0c05d8157b5dd222b58fa (patch) | |
tree | 7f2464f43ab4ff1e3cae8849f8b3e467ea6c21ac | |
parent | 40a6726836559089d63b0c6dc97a2b3e0cf13c8a (diff) |
No need to search for newline
We know it will always be the last character in line, and we know the
length of line from the return value.
-rw-r--r-- | src/todo.c | 18 |
1 files changed, 7 insertions, 11 deletions
@@ -75,7 +75,8 @@ void todo_list(void) { static const char *regular_text = "\e[0m"; char *line = NULL; - size_t line_len = 0; + size_t line_buff_size = 0; + ssize_t line_len = 0; errno = 0; todo_file = fopen("TODO", "r"); @@ -89,9 +90,10 @@ void todo_list(void) { } } - for (size_t i = 0; getline(&line, &line_len, todo_file) >= 0; i++) { + for (size_t i = 0; + (line_len = getline(&line, &line_buff_size, todo_file)) >= 0; i++) { // Remove trailing newline by setting it to NULL char. - line[strcspn(line, "\n")] = '\0'; + line[line_len - 1] = '\0'; if (line_len > 5) { // Print the index in bold @@ -104,9 +106,8 @@ void todo_list(void) { puts_strikethrough(line + 4); } } - - free(line); } + free(line); fclose(todo_file); } @@ -171,14 +172,9 @@ void todo_done(int argc, char **argv) { apply_func_to_line(done, done_index); } -void todo_raw(int argc, char **argv) { - /*open_todo_file();*/ - puts("raw"); - fclose(todo_file); -} +void todo_raw(int argc, char **argv) { fclose(todo_file); } void todo_sort(void) { - /*open_todo_file();*/ puts("sort"); fclose(todo_file); } |