Improve portability of dirtree and smex.