getcwd() for Kickstart 1.3 that attempts to follow POSIX spec
Features:
error checking, no extra allocations, no recursion, O(n)
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:
obtain a lock to MySubDir, write out riDbuSyM
obtain a lock to MyDir, append /riDyM
obtain a lock to MyPath, append :htaPyM
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.
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:
MySubDir
, write outriDbuSyM
MyDir
, append/riDyM
MyPath
, append:htaPyM
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.