From 7aa5fcb1a8ea079dd1c8d948a170ddc56fc1c53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 21 Apr 2015 22:24:01 +0200 Subject: Improve loading of files This fixes a segmentation fault when opening a directory. Also, opening a file you are not permitted to read, will now give an error, instead of showing the file as empty. Based on a patch by Willem van de Krol. --- editor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor.c b/editor.c index 7b0c7b2..9e3aa79 100644 --- a/editor.c +++ b/editor.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "editor.h" #include "util.h" @@ -298,7 +299,11 @@ static VisText *vis_text_new(Editor *ed, const char *filename) { } } - Text *data = text_load(filename && access(filename, F_OK) == 0 ? filename : NULL); + Text *data = text_load(filename); + if (!data && filename && errno == ENOENT) + data = text_load(NULL); + if (!data) + return NULL; if (filename) text_filename_set(data, filename); -- cgit v1.2.3