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: Cui Bixuan <cuibixuan at huawei dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- 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>, <zhuyanpeng at huawei dot com>
- Date: Sun, 6 Sep 2015 08:24:50 +0800
- 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> <87d1xyo740 dot fsf at igel dot home>
On 2015/9/4 17:40, Andreas Schwab wrote:
>>
>> 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.
>
Thank you for your explanation :-).
And there is another question, the testcase,
test.c:
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static int getafile(void);
static int
getafile(void)
{
int fd;
char temp[] = "/tmp/dup2XXXXXXXXX";
if ((fd = mkstemp(temp)) < 0)
err(1, "mkstemp");
remove(temp);
if (ftruncate(fd, 1024) != 0)
err(1, "ftruncate");
return (fd);
}
int
main(int argc, char *argv[])
{
struct rlimit rlp;
int orgfd, fd1, fd2, test = 0;
orgfd = getafile();
/* If dup(2) ever work? */
if ((fd1 = dup(orgfd)) < 0)
err(1, "dup");
printf("ok %d - dup(2) works\n", ++test);
if ((fd2 = fcntl(fd1, F_DUPFD)) < 0)
err(1, "fcntl(F_DUPFD)");
printf("ok %d - fcntl(F_DUPFD) works\n", ++test);
printf("pass\n");
return (0);
}
Compile and run it:
aarch64-linux-gnu-gcc test.c -o test -lpthread
./test
ok 1 - dup(2) works
test: fcntl(F_DUPFD): Invalid argument
I can find the error by 'strace ./test':
...
write(1, "ok 1 - dup(2) works\n", 20ok 1 - dup(2) works
) = 20
fcntl(4, F_DUPFD, 547995340800) = -1 EINVAL (Invalid argument)
write(2, "test: ", 6test: ) = 6
write(2, "fcntl(F_DUPFD)", 14fcntl(F_DUPFD)) = 14
write(2, ": ", 2: ) = 2
write(2, "Invalid argument\n", 17Invalid argument
) = 17
exit_group(1) = ?
+++ exited with 1 +++
then:
aarch64-linux-gnu-gcc test.c -o test
./test
ok 1 - dup(2) works
ok 2 - fcntl(F_DUPFD) works
pass
And If we add comment to 'printf("ok %d - dup(2) works\n", ++test);' , like this:
/* If dup(2) ever work? */
if ((fd1 = dup(orgfd)) < 0)
err(1, "dup");
// printf("ok %d - dup(2) works\n", ++test);
if ((fd2 = fcntl(fd1, F_DUPFD)) < 0)
err(1, "fcntl(F_DUPFD)");
printf("ok %d - fcntl(F_DUPFD) works\n", ++test);
compile and run:
aarch64-linux-gnu-gcc test.c -o test -lpthread
./test
ok 1 - fcntl(F_DUPFD) works
pass
Hope you can help me.
> Andreas.
>