MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test

Function test

test/unistd/unlink.c:51–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void test() {
52 int err;
53 char buffer[512];
54
55 //
56 // test unlink
57 //
58 err = unlink("noexist");
59 assert(err == -1);
60 assert(errno == ENOENT);
61
62 // Test non-existent parent
63 err = unlink("noexist/foo");
64 assert(err == -1);
65 assert(errno == ENOENT);
66
67 // Test empty pathname
68 err = unlink("");
69 assert(err == -1);
70 printf("errno: %s\n", strerror(errno));
71 assert(errno == ENOENT);
72
73 err = unlink("dir-readonly");
74 assert(err == -1);
75 printf("errno: %s\n", strerror(errno));
76
77 // emscripten uses 'musl' which is an implementation of the standard library for Linux-based systems
78#if defined(__linux__) || defined(__EMSCRIPTEN__)
79 // Here errno is supposed to be EISDIR, but it is EPERM for NODERAWFS on macOS.
80 // See https://github.com/emscripten-core/emscripten/issues/6121.
81 // Also, deno returns ENOTEMPTY:
82 // https://github.com/emscripten-core/emscripten/issues/26240
83 assert(errno == EISDIR || errno == EPERM || errno == ENOTEMPTY);
84#else
85 assert(errno == EPERM);
86#endif
87
88#ifndef SKIP_ACCESS_TESTS
89 err = unlink("dir-readonly/anotherfile");
90 printf("unlink: %d %s\n", err, strerror(errno));
91 assert(err == -1);
92 assert(errno == EACCES);
93#endif
94
95#ifndef NO_SYMLINK
96 // try unlinking the symlink first to make sure
97 // we don't follow the link
98 err = unlink("file1-link");
99 assert(!err);
100#endif
101 err = access("file1", F_OK);
102 assert(!err);
103#if !defined(NO_SYMLINK)
104 err = access("file1-link", F_OK);
105 assert(err == -1);
106#endif
107
108 err = unlink("file");

Callers 1

mainFunction · 0.70

Calls 8

printfFunction · 0.85
strerrorFunction · 0.85
accessFunction · 0.85
putsFunction · 0.85
unlinkFunction · 0.50
assertFunction · 0.50
rmdirFunction · 0.50
getcwdFunction · 0.50

Tested by

no test coverage detected