The basename() usage added in r322369 is wrong and caused us to store
the full path in the filepath buffer. If the path is absolute or
consists of just a filename, this happens to work. But if the path is
relative and contains at least one directory component, the openat()
call will fail.
Fix this, and add a quick and dirty regression test.