vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 4cec66216834d33a8cc43a8c63923bb2faa89684
parent 7634655d3a1d06b296fe2e7f30d946da7279c675
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 21 Apr 2015 22:24:01 +0200

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:
Meditor.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git 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);