3 ms·
I played around with glibc's getcwd() some time ago. With strace one can easily see how getcwd() works. If the current path is larger than PATH_MAX then the get
by leni536 10y ago
I played around with glibc's getcwd() some time ago. With strace one can easily see how getcwd() works. If the current path is larger than PATH_MAX then the getcwd syscall fails. Then as I recall glibc uses '..'s recursively so it never has to call a syscall with a long relative path.
If there is a non-user-readable directory in the path then the fallback method fails but the getcwd syscall works if the path is short enough.
Bash also "cheats" by caching the working directory and updating it on 'cd' commands.