core: Use libc::readlink function properly

The specification of readlink() says it's not guaranteed that the
returned contents of the symbolic link is null-terminated.
Merge pull request #4474 from tychosci/readlink_safe

core: Use libc::readlink function properly