Apply the basename()
function to the result of getcwd()
.
An alternative is to mess around getting the inode number of the current directory (.
) and then open and scan the parent directory (..
) looking for the name with the corresponding inode number. That gets tricky if the parent directory contains NFS auto-mount points (home directories, for example); you can end up auto-mounting an awful lot of file systems if you aren't careful (which is slow and mostly pointless).