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_link
12
13 # include <stdio.h>
14 # include <string.h>
15 # include <unistd.h>
16
17 int
18 main(void)
19 {
20 static const char sample_1_str[] = "link_sample_old";
21 static const char sample_2_str[] = "link_sample_new";
22
23 TAIL_ALLOC_OBJECT_CONST_ARR(char, sample_1, sizeof(sample_1_str));
24 TAIL_ALLOC_OBJECT_CONST_ARR(char, sample_2, sizeof(sample_2_str));
25 TAIL_ALLOC_OBJECT_CONST_ARR(char, short_1, sizeof(sample_1_str) - 1);
26 TAIL_ALLOC_OBJECT_CONST_ARR(char, short_2, sizeof(sample_2_str) - 1);
27
28 long rc;
29
30 memcpy(sample_1, sample_1_str, sizeof(sample_1_str));
31 memcpy(sample_2, sample_2_str, sizeof(sample_2_str));
32 memcpy(short_1, sample_1_str, sizeof(sample_1_str) - 1);
33 memcpy(short_2, sample_2_str, sizeof(sample_2_str) - 1);
34
35 rc = syscall(__NR_link, NULL, NULL);
36 # ifndef PATH_TRACING
37 printf("link(NULL, NULL) = %ld %s (%m)\n", rc, errno2name());
38 # endif
39
40 rc = syscall(__NR_link, short_1, NULL);
41 # ifndef PATH_TRACING
42 printf("link(%p, NULL) = %ld %s (%m)\n",
43 short_1, rc, errno2name());
44 # endif
45
46 rc = syscall(__NR_link, NULL, sample_1);
47 printf("link(NULL, \"%s\") = %ld %s (%m)\n",
48 sample_1_str, rc, errno2name());
49
50 rc = syscall(__NR_link, sample_1, short_2);
51 printf("link(\"%s\", %p) = %ld %s (%m)\n",
52 sample_1_str, short_2, rc, errno2name());
53
54 rc = syscall(__NR_link, short_1, sample_2);
55 # ifndef PATH_TRACING
56 printf("link(%p, \"%s\") = %ld %s (%m)\n",
57 short_1, sample_2_str, rc, errno2name());
58 # endif
59
60 rc = syscall(__NR_link, sample_1, sample_2);
61 printf("link(\"%s\", \"%s\") = %ld %s (%m)\n",
62 sample_1_str, sample_2_str, rc, errno2name());
63
64 puts("+++ exited with 0 +++");
65 return 0;
66 }
67
68 #else
69
70 SKIP_MAIN_UNDEFINED("__NR_link")
71
72 #endif