If you run library functions that set errno, it MAY be available to your exit routine, depending on what you do after errno gets set.
Your can can also deliberately set errno - if you're positive that no intervening call could set it to another value.
If you do that, be sure to use
#define EUSERVAL somevalue
where somevalue is NOT one already used by errno.h for the standard defined Exxxx messages.