On Mon, Mar 07, 2016 at 11:32:02AM +0800, Fei Jie wrote:
[...]
> --- /dev/null
> +++ b/tests/dup.c
> @@ -0,0 +1,27 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup

I think you can safely assume that dup syscall is available
and use dup() wrapper from libc.

> --- /dev/null
> +++ b/tests/dup2.c
> @@ -0,0 +1,28 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup2
> +
> +# include <errno.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +     const long int fd_old = (long int) 0xdeadbeefffffffff;
> +     const long int fd_new = (long int) 0xdeadbeeffffffffe;
> +     int rc = syscall(__NR_dup2, fd_old, fd_new);
> +     printf("dup2(%d, %d) = %d %s (%m)\n",
> +            (int)fd_old, (int)fd_new, rc,

The test for dup2 is fine, but please add space symbols after casts
consistently.

> --- /dev/null
> +++ b/tests/dup3.c
> @@ -0,0 +1,29 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_dup3
> +
> +# include <errno.h>
> +# include <fcntl.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> +     const long int fd_old = (long int) 0xdeadbeefffffffff;
> +     const long int fd_new = (long int) 0xdeadbeeffffffffe;
> +     int rc = syscall(__NR_dup3, fd_old, fd_new, O_CLOEXEC);
> +     printf("dup3(%d, %d, O_CLOEXEC) = %d %s (%m)\n",

Since O_CLOEXEC is a relatively new flag, we have to test it before use,
see tests/userfaultfd.c as an example.
Note that <fcntl.h> has to be included before the test.


-- 
ldv

Attachment: pgpFHY840L8_k.pgp
Description: PGP signature

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://makebettercode.com/inteldaal-eval
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to