The old core of PHP is very close to the libc function it offers, and so you will do that in a similar way that you do that in C : call error_get_last(), which gives you the details of the last error.
How do I do "errno == EXISTS" like in C? This is bit I need. The issue for this was closed as essentially as wontfix: https://bugs.php.net/bug.php?id=49396