evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / ca / cano / allow-read-only-store-help-page.patch
blob174d15fc82c69e0f0a8f2b240e5d8c3958fc624b
1 diff --git a/src/main.c b/src/main.c
2 index 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;
9 - char *env = getenv("HOME");
10 - if(env == NULL) CRASH("could not get HOME");
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);
18 // check if file exists
19 struct stat st;
20 diff --git a/src/tools.c b/src/tools.c
21 index 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) {
26 void handle_save(Buffer *buffer) {
27 FILE *file = fopen(buffer->filename, "w");
29 + if (file == NULL)
30 + return;
31 fwrite(buffer->data.data, buffer->data.count, sizeof(char), file);
32 fclose(file);
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);