Make safe_open() treat trailing slashes like open().

(cherry picked from commit 027257631489a04cce1d77ed66d49893eff68475)