diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 22:24:01 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 22:24:01 +0200 |
| commit | 7aa5fcb1a8ea079dd1c8d948a170ddc56fc1c53d (patch) | |
| tree | 2fede981b4ab023ea670f6bb29eeae60bb56970e | |
| parent | e765721a9d2cafd0370d28ea9f3321a475528d54 (diff) | |
| download | vis-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.
| -rw-r--r-- | editor.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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); |
