[WIP] Change function interfaces and implementations to use errno.h constants

This PR changes everything. :-)