Given the following example parsing a string that only contains valid numeric characters, but is to large for type long int[0].
char *endptr = NULL;
long int val = strtol("0xfffffffffffffffffffffffff", &endptr, 0);
It is my understanding that the only way to catch this error is to check if errno is set[1].
Even though errno is supposed to be thread safe[2], this is not the case in most real-time embedded systems[3] where errno is a global int - is this correct? In that case, errno can not be trusted as it could have been modified from interrupt[4] context.
Is there a way to catch this error without using errno or is there another workaround? Implementing a custom strto* do not seems like sane solution, but perhaps there is no other way?
[0] Similar example could be constructed for other functions in strto* family such as strtod, strtof, strtold, strtoll, strtoul and strtoull.
[1] http://man7.org/linux/man-pages/man3/strtol.3.html
[2] Is errno thread-safe? (also related question)
[3] Example in a "bare metal" project or in a low level RTOS such as Apache mynewt, Zephyr or FreeRTOS.
[4] Modified from interrupt or other context that the OS scheduler might provide. I believe these typically only manages the stack and nothing more.