2 * Copyright (c) 2015 Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
3 * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2015-2019 The strace developers.
7 * SPDX-License-Identifier: GPL-2.0-or-later
18 # define PREFIX "test.readlink"
19 # define TARGET (PREFIX ".target")
20 # define LINKPATH (PREFIX ".link")
25 const char * const fname = tail_memdup(LINKPATH, sizeof(LINKPATH));
26 const char * const hex_fname =
27 hexquote_strndup(fname, sizeof(LINKPATH) - 1);
29 const unsigned int size = sizeof(TARGET) - 1;
30 char * const buf = tail_alloc(size);
34 long rc = syscall(__NR_readlink, fname, buf, size);
35 printf("readlink(\"%s\", %p, %u) = -1 ENOENT (%m)\n",
36 hex_fname, buf, size);
38 if (symlink(TARGET, fname))
39 perror_msg_and_fail("symlink");
41 rc = syscall(__NR_readlink, fname, buf, size);
47 const char * const hex_buf = hexquote_strndup(buf, size);
48 printf("readlink(\"%s\", \"%s\", %u) = %u\n",
49 hex_fname, hex_buf, size, size);
52 perror_msg_and_fail("unlink");
54 puts("+++ exited with 0 +++");
60 SKIP_MAIN_UNDEFINED("__NR_readlink")