On Mon Dec 2 22:17:00 2024 +0000, Gabriel Ivăncescu wrote:
Yes that's what I meant. Is there a better way to detect that? There is probably no fundamental improvements in I/O aspect, although I believe the name `is_same_dentry` is much clearer. I like this version better:
```c /* Determine if two paths have the same parent directories and basenames. */ static int is_same_dentry( const char *pathname1, const char *pathname2 ) { const char *lastslash1 = strrchr(pathname1, '/'); const char *lastslash2 = strrchr(pathname2, '/'); char *dirname1 = NULL, dirname2 = NULL; int res; /* Last slash must be preceded by a non-slash character */ assert( lastslash1 && lastslash1 != pathname1 && lastslash1[-1] != '/' ); assert( lastslash2 && lastslash2 != pathname2 && lastslash2[-1] != '/' ); /* different basenames imply different dentries */ if (strcmp( lastslash1 + 1, lastslash2 + 1 ) != 0) return 0; res = -1; if ((dirname1 = memdup( pathname1, lastslash1 + 1 - pathname1 )) && (dirname2 = memdup( pathname2, lastslash2 + 1 - pathname2 ))) { struct stat st1, st2; dirname1[lastslash1 - pathname1] = '\0'; dirname2[lastslash2 - pathname2] = '\0'; if (stat(dirname1, &st1) || stat(dirname2, &st2)) { file_set_error(); } else { res = st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; } } free(dirname2); free(dirname1); return res; } ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/6855#note_93894