Made a lot of changes to error and return values.

 - Added a hidden/static variable holding value of last error that occured.
 - Added functions that allow seeing the last error, clear the error variable and print error message to stderr.
 - Made enums with return values for functions covering error values and special cases.
 - Made every function use these enums whenever possible and set the hidden variable when error occurs.
 - Restructured functions a bit to make use of these values better in them.

Reasoning:
----------

Mainly to standardize return values for functions so there is no overlap in what each return value means. Previously there was some overlap with -2 and possibly more values. But also to make it possible to check what error occured inside functions that can't return the error value directly and must return NULL or something else when error happens. Another reason is to make the return values be much easier to read and check instead of the values under them, which you would sometimes have to check with the documentation to see what they mean.