vis

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

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

commit 05045f93d748ddfa7838216de32f48ac7fcb36b6
parent 6d55b08ff994e318c155d3e7d3b9dd2d0340a792
Author: Tom Schwindl <schwindl@posteo.de>
Date:   Tue, 19 Jul 2022 15:26:50 +0000

vis: Compare non-existing files by name and existing files by inode

Diffstat:
Mvis.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/vis.c b/vis.c @@ -179,19 +179,26 @@ err: static File *file_new(Vis *vis, const char *name) { char *name_absolute = NULL; + bool cmp_names = 0; struct stat new; if (name) { if (!(name_absolute = absolute_path(name))) return NULL; - if (stat(name_absolute, &new) && errno != ENOENT) - return NULL; + + if (stat(name_absolute, &new)) { + if (errno != ENOENT) { + free(name_absolute); + return NULL; + } + cmp_names = 1; + } File *existing = NULL; /* try to detect whether the same file is already open in another window */ - for (File *file = vis->files; file; file = file->next) { - if (file->name && file->stat.st_dev == new.st_dev && - file->stat.st_ino == new.st_ino) { + for (File *file = vis->files; file && file->name; file = file->next) { + if (cmp_names && strcmp(file->name, name_absolute) == 0 || + file->stat.st_dev == new.st_dev && file->stat.st_ino == new.st_ino) { existing = file; break; }