aboutsummaryrefslogtreecommitdiff
path: root/editor.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-04-21 22:24:01 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-04-21 22:24:01 +0200
commit7aa5fcb1a8ea079dd1c8d948a170ddc56fc1c53d (patch)
tree2fede981b4ab023ea670f6bb29eeae60bb56970e /editor.c
parente765721a9d2cafd0370d28ea9f3321a475528d54 (diff)
downloadvis-7aa5fcb1a8ea079dd1c8d948a170ddc56fc1c53d.tar.gz
vis-7aa5fcb1a8ea079dd1c8d948a170ddc56fc1c53d.tar.xz
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.
Diffstat (limited to 'editor.c')
-rw-r--r--editor.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/editor.c b/editor.c
index 7b0c7b2..9e3aa79 100644
--- a/editor.c
+++ b/editor.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
+#include <errno.h>
#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);