according documentation:
On success, the function returns the converted integral number as a long int value. If no valid conversion could be perfor
You can either check the errno or pass a non-NULL value for the second argument and compare its resulting value to str, like:
errno
str
char * endptr; long result = strtol(str, &endptr, 10); if (endptr > str) { // Use result... }