Accept arbitrarily long lists of dirname() calls

Change-Id: I3ffdb57e9339c7ce7a07cdbf45eca4e4b4bb4c1e