Bug 241254 - atoi(3) wrongly states that atoi() is equivalent to (int)strtol(nptr, (char **)NULL, 10);
Summary: atoi(3) wrongly states that atoi() is equivalent to (int)strtol(nptr, (char *...
Status: Closed Not A Bug
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-15 03:11 UTC by Yuri Victorovich
Modified: 2019-10-15 16:23 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2019-10-15 03:11:31 UTC
strtol(3) parses the string as 'long' and long is 64-bit on amd64, and int is 32-bit, so they can't be equivalent.

> DESCRIPTION
>      The atoi() function converts the initial portion of the string pointed to
>      by nptr to int representation.
> 
>      It is equivalent to:
> 
>            (int)strtol(nptr, (char **)NULL, 10);
> 
>      The atoi() function has been deprecated by strtol() and should not be
>      used in new code.
Comment 1 Brooks Davis freebsd_committer freebsd_triage 2019-10-15 16:23:20 UTC
The implementation of atoi() is literally:

int
atoi(const char *str)
{
        return (int)strtol(str, NULL, 10);
}

so this statement is entirely correct.