1 /*
2 * Copyright (c) 2016-2023 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "tests.h"
9 #include "scno.h"
10
11 #ifdef __NR_symlink
12
13 # include <stdio.h>
14 # include <string.h>
15 # include <unistd.h>
16
17 int
18 main(int ac, char **av)
19 {
20 static const char sample_str[] = "symlink.sample";
21 static const char target_str[] = "symlink.target";
22
23 TAIL_ALLOC_OBJECT_CONST_ARR(char, sample, sizeof(sample_str));
24 TAIL_ALLOC_OBJECT_CONST_ARR(char, target, sizeof(target_str));
25 TAIL_ALLOC_OBJECT_CONST_ARR(char, short_sample, sizeof(sample_str) - 1);
26 TAIL_ALLOC_OBJECT_CONST_ARR(char, short_target, sizeof(target_str) - 1);
27
28 long rc;
29
30 memcpy(sample, sample_str, sizeof(sample_str));
31 memcpy(target, target_str, sizeof(target_str));
32 memcpy(short_sample, sample_str, sizeof(sample_str) - 1);
33 memcpy(short_target, target_str, sizeof(target_str) - 1);
34
35 rc = syscall(__NR_symlink, NULL, NULL);
36 # ifndef PATH_TRACING
37 printf("symlink(NULL, NULL) = %s\n", sprintrc(rc));
38 # endif
39
40 rc = syscall(__NR_symlink, NULL, sample);
41 printf("symlink(NULL, \"%s\") = %s\n", sample, sprintrc(rc));
42
43 rc = syscall(__NR_symlink, short_target, sample);
44 printf("symlink(%p, \"%s\") = %s\n",
45 short_target, sample, sprintrc(rc));
46
47 rc = syscall(__NR_symlink, target, short_sample);
48 # ifndef PATH_TRACING
49 printf("symlink(\"%s\", %p) = %s\n",
50 target, short_sample, sprintrc(rc));
51 # endif
52
53 rc = syscall(__NR_symlink, sample, av[0]);
54 # ifndef PATH_TRACING
55 printf("symlink(\"%s\", \"%s\") = %s\n", sample, av[0], sprintrc(rc));
56 # endif
57
58 rc = syscall(__NR_symlink, target, sample);
59 printf("symlink(\"%s\", \"%s\") = %s\n", target, sample, sprintrc(rc));
60
61 puts("+++ exited with 0 +++");
62 return 0;
63 }
64
65 #else
66
67 SKIP_MAIN_UNDEFINED("__NR_symlink")
68
69 #endif