2 * Copyright (c) 2015 Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
3 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
6 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include <asm/unistd.h>
17 # define PREFIX "test.readlink"
18 # define TARGET (PREFIX ".target")
19 # define LINKPATH (PREFIX ".link")
24 const char * const fname = tail_memdup(LINKPATH, sizeof(LINKPATH));
25 const char * const hex_fname =
26 hexquote_strndup(fname, sizeof(LINKPATH) - 1);
28 const unsigned int size = sizeof(TARGET) - 1;
29 char * const buf = tail_alloc(size);
33 long rc = syscall(__NR_readlink, fname, buf, size);
34 printf("readlink(\"%s\", %p, %u) = -1 ENOENT (%m)\n",
35 hex_fname, buf, size);
37 if (symlink(TARGET, fname))
38 perror_msg_and_fail("symlink");
40 rc = syscall(__NR_readlink, fname, buf, size);
46 const char * const hex_buf = hexquote_strndup(buf, size);
47 printf("readlink(\"%s\", \"%s\", %u) = %u\n",
48 hex_fname, hex_buf, size, size);
51 perror_msg_and_fail("unlink");
53 puts("+++ exited with 0 +++");
59 SKIP_MAIN_UNDEFINED("__NR_readlink")