News for hackers. Stuff that matters.
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by ksherlock on Wednesday May 21, 2025 @04:31PM (#44056003)
Your errno checks aren't correct.

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;
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by kazinator on Wednesday May 21, 2025 @07:42PM (#44057384)
No ISO C standard library function sets errno to zero, but functions not in the standard library are not so obliged.

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.

Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by ben0x539 on Wednesday May 21, 2025 @04:42PM (#44056123)
Doesn't it set errno to 0 first thing?
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by ksherlock on Wednesday May 21, 2025 @06:10PM (#44056778)
ahh, you're right. It's still polite to save and restore though :)
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by rantouan on Thursday May 22, 2025 @10:38AM (#44062533)
not bad, check my suggestion for pull request, above
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by rantouan on Thursday May 22, 2025 @10:36AM (#44062512)
hello, errno is set to 0 first thing.

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;
    ...
```
Re:Ratatoi is a C libary that wraps stdlib's strtol (as atoi... by rantouan on Thursday May 22, 2025 @10:38AM (#44062525)
For the restoring part, could you make a pull request please ? Open source strength is that we work together on things.