bebbo / libnix

libnix (v4): a C link library for AmigaOS/m68k
15 stars 9 forks source link

libnix13: Add a POSIX-compliant implementation of getcwd #78

Closed Z4JC closed 5 months ago

Z4JC commented 5 months ago

getcwd() for Kickstart 1.3 that attempts to follow POSIX spec Features:

We start from the current directory and walk up to the root. Imagine we are in MyPath:MyDir/MySubDir We obtain a FileInfoBlock to MySubDir, then MyDir then MyPath. To avoid allocating extra stuff, holding multiple locks, recursing, etc. we write out all the names as we encounter them in reverse.

Example:

Now we have: riDbuSyM/riDyM:htaPyM then we reverse the string at the end: MyPath:MyDir/MySubDir This requires no extra memory bookkeeping or recursion.