Fix failure to open paths ending in a slash.

Redmine #3905.
Fix incorrect return value for empty string in safe_open.
Tiny optimization in safe_open.

We already know that next_component is neither null nor empty in the
second branch, because of 7f137f0ad5.
Merge pull request #1243 from kacfengine/safe_open_fixes

[Redmine #3905] Safe open fixes