examples: Do not assume positive errno macros

Some functions were returning e.g. -ENOMEM and the caller would check
for negative return values. However, on Haiku, contrary to modern
standards, these macros are negative, so this logic would fail. In any
case, change the function to return -1 instead. For good measure also
set errno to the appropriate value, although it is not used in the
current code.

This was discovered on Haiku builds because the value for ENOMEM is
INT_MIN which cannot be negated without overflow.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
4 files changed