aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorTom Schwindl <schwindl@posteo.de>2022-07-19 15:26:50 +0000
committerFelix Van der Jeugt <felix.vanderjeugt@posteo.net>2022-07-23 10:36:25 +0200
commit7c22e881df5a4270ee0f1c112bda43e056949d88 (patch)
tree8f5eaff286afe5990e1688bad606bd4bec3577b1 /vis.c
parent1ca937518ed5ca00e18e5e59e1fef0d9bd628e16 (diff)
downloadvis-7c22e881df5a4270ee0f1c112bda43e056949d88.tar.gz
vis-7c22e881df5a4270ee0f1c112bda43e056949d88.tar.xz
vis: Compare non-existing files by name and existing files by inode
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/vis.c b/vis.c
index 152a594..6ee9f22 100644
--- 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;
}