fix: distinct fake inodes for directories in stat()
stat() synthesized path-hash inodes for regular files but left st_ino = 0 for directories. GCC's include-path setup deduplicates directories by (st_dev, st_ino), so every directory on MontaukOS compared equal and cc1plus silently dropped all C++ include dirs except the first - <iostream> resolved but the target-specific bits/c++config.h directory was gone. Directories now get the same path-hash inodes as files. (Different spellings of one directory hash differently; the harmless direction - a dir may be searched twice, never dropped.) Native GCC relinked against the fixed libc. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -2305,6 +2305,16 @@ int stat(const char *path, struct stat *buf) {
|
||||
if (_path_is_directory(path)) {
|
||||
buf->st_mode = S_IFDIR;
|
||||
buf->st_size = 0;
|
||||
/* Directories need distinct fake inodes too: GCC's include
|
||||
path setup deduplicates directories by (st_dev, st_ino), so
|
||||
leaving 0 here made every directory "the same" and all but
|
||||
one include dir was silently dropped. */
|
||||
unsigned long ino = 5381;
|
||||
for (const char *p = path; *p; p++) {
|
||||
ino = ino * 33 + (unsigned char)*p;
|
||||
}
|
||||
buf->st_ino = ino | 1;
|
||||
buf->st_nlink = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user