aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorTom Schwindl <schwindl@posteo.de>2022-07-10 19:30:22 +0000
committerFelix Van der Jeugt <felix.vanderjeugt@posteo.net>2022-07-12 22:58:14 +0200
commitcbeda11801c95687498e2deb6a0144b562581d16 (patch)
tree4f2b161fc325fb3adb8a055472249770300fd92e /vis.c
parenteb96e0ce8143804f5a7a37eb76a4b86d8871dd76 (diff)
downloadvis-cbeda11801c95687498e2deb6a0144b562581d16.tar.gz
vis-cbeda11801c95687498e2deb6a0144b562581d16.tar.xz
vis: Compare inodes instead of filenames
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/vis.c b/vis.c
index cc61754..152a594 100644
--- a/vis.c
+++ b/vis.c
@@ -179,14 +179,19 @@ err:
static File *file_new(Vis *vis, const char *name) {
char *name_absolute = NULL;
+ struct stat new;
+
if (name) {
if (!(name_absolute = absolute_path(name)))
return NULL;
+ if (stat(name_absolute, &new) && errno != ENOENT)
+ return NULL;
+
File *existing = NULL;
- /* try to detect whether the same file is already open in another window
- * TODO: do this based on inodes */
+ /* 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 && strcmp(file->name, name_absolute) == 0) {
+ if (file->name && file->stat.st_dev == new.st_dev &&
+ file->stat.st_ino == new.st_ino) {
existing = file;
break;
}