by ksherlock · 1y ago · 0 comments
errno is only set on an error. It's not cleared on success. If errno was previously set, the function will always abort(). So you need to do something like:
int saved_errno = errno;
errno = 0;
....
errno = saved_errno;
return aInt;Functions that clobber errno to zero make it impossible to call several functions and use a nonzero value of errno to conclude that one or more of them went wrong.
If you don't think that such code is a good idea (for instance because you believe that every function that can fail should be checked for its specific error), then you probably have nothing against functions which clobber errno to zero.
I added now a "/** * * */" separator to make it even more clear.
I don't know, but I like separating things like that, I think it's handy for cases like now that setting the errno was kind of mixed with vars initialization.
```
errno = 0;
char *strtolEndptr;
...
```->
```
errno = 0;
/*** * * ***/
char *strtolEndptr;
...
```