]> granicus.if.org Git - strace/blob - readlink.c
Add support for long options
[strace] / readlink.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 2006 Ulrich Drepper <drepper@redhat.com>
7  * Copyright (c) 2006 Bernhard Kaindl <bk@suse.de>
8  * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
9  * Copyright (c) 2014-2019 The strace developers.
10  * All rights reserved.
11  *
12  * SPDX-License-Identifier: LGPL-2.1-or-later
13  */
14
15 #include "defs.h"
16
17 static int
18 decode_readlink(struct tcb *tcp, int offset)
19 {
20         if (entering(tcp)) {
21                 printpath(tcp, tcp->u_arg[offset]);
22                 tprints(", ");
23         } else {
24                 if (syserror(tcp))
25                         printaddr(tcp->u_arg[offset + 1]);
26                 else
27                         /* Used to use printpathn(), but readlink
28                          * neither includes NUL in the returned count,
29                          * nor actually writes it into memory.
30                          * printpathn() would decide on printing
31                          * "..." continuation based on garbage
32                          * past return buffer's end.
33                          */
34                         printstrn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
35                 tprintf(", %" PRI_klu, tcp->u_arg[offset + 2]);
36         }
37         return 0;
38 }
39
40 SYS_FUNC(readlink)
41 {
42         return decode_readlink(tcp, 0);
43 }
44
45 SYS_FUNC(readlinkat)
46 {
47         if (entering(tcp)) {
48                 print_dirfd(tcp, tcp->u_arg[0]);
49                 tprints(", ");
50         }
51         return decode_readlink(tcp, 1);
52 }