Implemented safe_open() in order to avoid symlink race conditions.

It makes sure that we do not follow unsafe symlinks, that is a link
that belongs to a user, but has a target owned by a different user.
It does this in a way that avoids race conditions (between testing if
a file is a link, and opening that file, there is a small window of
opportunity).

Also implements safe_chdir(), to also safeguard chdir() operations.

Fixes issue #3693.
Merge pull request #1115 from kacfengine/safe_open

Implemented safe_open() in order to avoid symlink race conditions.
Work around fdopendir() missing on some platforms.
Merge pull request #1117 from kacfengine/safe_open

Work around fdopendir() missing on some platforms.
Add missing header.
Merge pull request #1121 from kacfengine/safe_open

Add missing header.
Don't use O_DIRECTORY flag, which is Linux specific.

Directories will fail when we try to chdir into them anyway, so all
we lose is the early warning.
Switch back to test folder after each test.

Otherwise the test framework may try to write into the wrong
directory.
Merge pull request #1123 from kacfengine/safe_open

Some fixes to the safe_open() function.
Fix format strings for uint64_t types
const'ify VerifyFinderType
Fix PromiseResultUpdate invocation in VerifyFinderType
Update libvirt stub
Fix wrong type passed to variable internalization step
Add FUNC_UNUSED attribute
Mark unused functions from generated PEG grammar as such
Const'ify LastSaw
Add return false to catch-all clause: assert() is NOOP in NDEBUG
Don't check return code from PromiseTypeAppendPromise

It is guaranteed to either crash or return non-NULL
Cover default case for compiler's peace