nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 42 lines 1.5 kB view raw
1diff --git a/src/main.c b/src/main.c 2index 993a76f..de5b2c5 100644 3--- a/src/main.c 4+++ b/src/main.c 5@@ -6,12 +6,8 @@ _Static_assert(sizeof(string_modes)/sizeof(*string_modes) == MODE_COUNT, "Number 6 char *get_help_page(char *page) { 7 if (page == NULL) return NULL; 8 9- char *env = getenv("HOME"); 10- if(env == NULL) CRASH("could not get HOME"); 11- 12- char *help_page = calloc(128, sizeof(char)); 13- if (help_page == NULL) CRASH("could not calloc memory for help page"); 14- snprintf(help_page, 128, "%s/.local/share/cano/help/%s", env, page); 15+ char *help_page; 16+ asprintf(&help_page, "@help@/%s", page); 17 18 // check if file exists 19 struct stat st; 20diff --git a/src/tools.c b/src/tools.c 21index 220d7a1..4ce211e 100644 22--- a/src/tools.c 23+++ b/src/tools.c 24@@ -63,6 +63,9 @@ void free_undo_stack(Undo_Stack *undo) { 25 26 void handle_save(Buffer *buffer) { 27 FILE *file = fopen(buffer->filename, "w"); 28+ 29+ if (file == NULL) 30+ return; 31 fwrite(buffer->data.data, buffer->data.count, sizeof(char), file); 32 fclose(file); 33 } 34@@ -72,7 +75,7 @@ Buffer *load_buffer_from_file(char *filename) { 35 size_t filename_s = strlen(filename)+1; 36 buffer->filename = calloc(filename_s, sizeof(char)); 37 strncpy(buffer->filename, filename, filename_s); 38- FILE *file = fopen(filename, "a+"); 39+ FILE *file = fopen(filename, "r"); 40 if(file == NULL) CRASH("Could not open file"); 41 fseek(file, 0, SEEK_END); 42 size_t length = ftell(file);