This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: There is a problem when I compile the case with -lcrypt
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: Cui Bixuan <cuibixuan at huawei dot com>
- Cc: <libc-alpha at sourceware dot org>, <zhanyongming at huawei dot com>, Li Jinyue <lijinyue at huawei dot com>, Ji Qin <jiqin dot ji at huawei dot com>
- Date: Fri, 04 Sep 2015 11:40:15 +0200
- Subject: Re: There is a problem when I compile the case with -lcrypt
- Authentication-results: sourceware.org; auth=none
- References: <55E94AF9 dot 5050700 at huawei dot com>
Cui Bixuan <cuibixuan@huawei.com> writes:
> int main() {
> char *c, *s;
> long int i;
>
> s="9223372036854775807";
> strtol(s, &c, 0);
>
> printf("errno=%d\n",errno);
>
> return 0;
> }
>
> Then I compile and run it in arm64 system:
>
> aarch64-linux-gnu-gcc test.c -o test
> aarch64-linux-gnu-gcc test.c -o test-1 -lcrypt
>
> ./test
> errno=0
>
> ./test-1
> errno=2
>
> I don't know why? Is this a problem?
The value of errno is unspecified except after a function call that is
documented to set errno _and_ that function call returned a failure
condition. Additionally, some functions like strtol are documented to
not modify errno if they return sucessfully. If you want to check for
failure for such a function you need to set errno to zero before the
call.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."