The manpage of errno
states:
errno
is never set to zero by any system call or library function
but you can set it to zero as stated in the manpage of strtol()
the calling program should set
errno
to 0 before the call, and then determine if an error occurred by checking whethererrno
has a nonzero value after the call.
so just add
errno = 0;
before calling strtol()