|
5 | 5 | * found in the LICENSE file. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +#include <assert.h> |
8 | 9 | #include <stdio.h> |
9 | 10 | #include <errno.h> |
10 | 11 | #include <unistd.h> |
|
14 | 15 | #include <limits.h> |
15 | 16 | #include <stdlib.h> |
16 | 17 |
|
17 | | -int main() { |
| 18 | +void setup() { |
18 | 19 | EM_ASM( |
19 | | - fs.mkdirSync('./new-directory', '0777'); |
20 | | - fs.writeFileSync('./new-directory/test', 'Link it'); |
21 | | - fs.symlinkSync(fs.realpathSync('./new-directory'), './symlink'); |
| 20 | + fs.mkdirSync('new-directory', '0777'); |
| 21 | + fs.writeFileSync('new-directory/test', 'Link it'); |
| 22 | + fs.symlinkSync(fs.realpathSync('new-directory'), 'symlink'); |
22 | 23 |
|
23 | 24 | FS.mkdir('working'); |
24 | 25 | FS.mount(NODEFS, { root: '.' }, 'working'); |
25 | 26 |
|
26 | 27 | FS.mkdir('direct-link'); |
27 | | - FS.mount(NODEFS, { root: './symlink' }, 'direct-link'); |
| 28 | + FS.mount(NODEFS, { root: 'symlink' }, 'direct-link'); |
28 | 29 | ); |
| 30 | +} |
29 | 31 |
|
30 | | - { |
31 | | - const char* path = "/working/symlink/test"; |
32 | | - printf("reading %s\n", path); |
| 32 | +int main() { |
| 33 | + setup(); |
33 | 34 |
|
34 | | - FILE* fd = fopen(path, "r"); |
35 | | - if (fd == NULL) { |
36 | | - printf("failed to open file %s\n", path); |
37 | | - } |
38 | | - else { |
39 | | - char buffer[8]; |
40 | | - fread(buffer, 1, 7, fd); |
41 | | - buffer[7] = 0; |
42 | | - printf("buffer is %s\n", buffer); |
43 | | - fclose(fd); |
44 | | - } |
45 | | - } |
| 35 | + char buf[1024]; |
| 36 | + readlink("/working/symlink", buf, 1024); |
| 37 | + printf("readlink: %s\n", buf); |
46 | 38 |
|
47 | | - printf("\n"); |
| 39 | + FILE* fd = fopen("/working/symlink/test", "r"); |
| 40 | + assert(fd); |
| 41 | + char buffer[8] = {0}; |
| 42 | + int rtn = fread(buffer, 1, 7, fd); |
| 43 | + assert(rtn == 7); |
| 44 | + printf("buffer is '%s'\n", buffer); |
| 45 | + fclose(fd); |
48 | 46 |
|
49 | | - { |
50 | | - const char* path = "/direct-link/test"; |
51 | | - printf("reading %s\n", path); |
| 47 | + // This should fail, since it resolves to ../new-directory which is not |
| 48 | + // mounted |
| 49 | + fd = fopen("/direct-link/test", "r"); |
| 50 | + assert(fd == NULL); |
52 | 51 |
|
53 | | - FILE* fd = fopen(path, "r"); |
54 | | - if (fd != NULL) { |
55 | | - // This should not happen, it resolves to ../new-directory which is not mounted |
56 | | - printf("opened file %s\n", path); |
57 | | - fclose(fd); |
58 | | - } |
59 | | - else { |
60 | | - printf("failed to open file %s\n", path); |
61 | | - } |
62 | | - } |
63 | | - |
64 | 52 | return 0; |
65 | 53 | } |
0 commit comments