1 /*
2 * Copyright (c) 1999-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 #include "defs.h"
9
10 static int
11 dup_123(struct tcb *const tcp, const int newfd_arg, const int flags_arg)
12 {
13 /* oldfd */
14 printfd(tcp, tcp->u_arg[0]);
15
16 if (newfd_arg > 0) {
17 tprint_arg_next();
18 /* newfd */
19 printfd(tcp, tcp->u_arg[newfd_arg]);
20
21 if (flags_arg > 0) {
22 tprint_arg_next();
23 /* flags */
24 printflags(open_mode_flags, tcp->u_arg[flags_arg],
25 "O_???");
26 }
27 }
28
29 return RVAL_DECODED | RVAL_FD;
30 }
31
32 SYS_FUNC(dup)
33 {
34 return dup_123(tcp, -1, -1);
35 }
36
37 SYS_FUNC(dup2)
38 {
39 return dup_123(tcp, 1, -1);
40 }
41
42 SYS_FUNC(dup3)
43 {
44 return dup_123(tcp, 1, 2);
45 }