Skip to content

Commit 751652c

Browse files
committed
Update test
1 parent 5bd422e commit 751652c

File tree

1 file changed

+24
-39
lines changed

1 file changed

+24
-39
lines changed

test/unistd/write_broken_link.c

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
1-
#include <stdlib.h>
21
#include <errno.h>
32
#include <fcntl.h>
43
#include <stdio.h>
54
#include <string.h>
65
#include <unistd.h>
76

87

9-
char* join_path(const char* path1, const char* path2) {
10-
int len1 = strlen(path1);
11-
int len2 = strlen(path2);
12-
char* result = malloc(len1 + len2 + 2);
13-
memcpy(result, path1, len1);
14-
result[len1] = '/';
15-
memcpy(result + len1 + 1, path2, len2);
16-
return result;
17-
}
18-
198
int main() {
20-
char template[] = "/tmp/tmpdir.XXXXXX";
21-
char *tmpdir = mkdtemp(template);
22-
char* p1 = join_path(tmpdir, "test");
23-
char* p2 = join_path(tmpdir, "test2");
9+
char* p1 = "link_source";
10+
char* p2 = "link_target";
2411

25-
int res = symlink(p2, p1);
26-
printf("link result: %d\n", res);
27-
int src_fd = open(p1, O_CREAT | O_WRONLY, 0777);
28-
printf("source_fd: %d, errno: %d %s\n", src_fd, errno, strerror(errno));
29-
write(src_fd, "abc", 3);
30-
close(src_fd);
31-
{
32-
int target_fd = open(p2, O_RDONLY);
33-
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
34-
char buf[10];
35-
read(target_fd, buf, 10);
36-
printf("buf: '%s'\n", buf);
37-
close(target_fd);
38-
}
39-
{
40-
int target_fd = open(p1, O_RDONLY);
41-
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
42-
char buf[10];
43-
read(target_fd, buf, 10);
44-
printf("buf: '%s'\n", buf);
45-
close(target_fd);
46-
}
47-
free(p1);
48-
free(p2);
12+
int res = symlink(p2, p1);
13+
printf("link result: %d\n", res);
14+
int src_fd = open(p1, O_CREAT | O_WRONLY, 0777);
15+
printf("source_fd: %d, errno: %d %s\n", src_fd, errno, strerror(errno));
16+
write(src_fd, "abc", 3);
17+
close(src_fd);
18+
{
19+
int target_fd = open(p2, O_RDONLY);
20+
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
21+
char buf[10];
22+
read(target_fd, buf, 10);
23+
printf("buf: '%s'\n", buf);
24+
close(target_fd);
25+
}
26+
{
27+
int target_fd = open(p1, O_RDONLY);
28+
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
29+
char buf[10];
30+
read(target_fd, buf, 10);
31+
printf("buf: '%s'\n", buf);
32+
close(target_fd);
33+
}
4934
}

0 commit comments

Comments
 (0)