aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-07-13 20:17:19 -0700
committerAnthony Pesch <inolen@gmail.com>2013-07-13 20:17:19 -0700
commite1d208d8caff0e0afee7cbe1eebde12811c7d8d8 (patch)
tree4b49a36643abd4c5e7057c30806f62e1e839b12a
parentd2317359b2bb02ed4c8f773867c470c5a92a181e (diff)
open should not set EISDIR when opening an existing directory with O_CREAT
-rw-r--r--src/library.js2
-rw-r--r--tests/fcntl-open/output.txt10
-rw-r--r--tests/fcntl-open/src.c64
-rwxr-xr-xtests/runner.py13
4 files changed, 58 insertions, 31 deletions
diff --git a/src/library.js b/src/library.js
index f9cfe68f..8ef37c77 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1211,7 +1211,7 @@ LibraryManager.library = {
___setErrNo(ERRNO_CODES.EEXIST);
return -1;
}
- if ((isWrite || isCreate || isTruncate) && target.isFolder) {
+ if ((isWrite || isTruncate) && target.isFolder) {
___setErrNo(ERRNO_CODES.EISDIR);
return -1;
}
diff --git a/tests/fcntl-open/output.txt b/tests/fcntl-open/output.txt
index 314ae880..07b106ac 100644
--- a/tests/fcntl-open/output.txt
+++ b/tests/fcntl-open/output.txt
@@ -19,8 +19,8 @@ errno: 0
st_mode: 0100000
EXISTING FOLDER 0,1
-success: 0
-errno: 21
+success: 1
+errno: 0
st_mode: 040000
NON-EXISTING 0,1
@@ -139,8 +139,8 @@ errno: 0
st_mode: 0100000
EXISTING FOLDER 0,9
-success: 0
-errno: 21
+success: 1
+errno: 0
st_mode: 040000
NON-EXISTING 0,9
@@ -720,4 +720,4 @@ st_mode: 0100000
CREAT
success: 1
-errno: 0
+errno: 0 \ No newline at end of file
diff --git a/tests/fcntl-open/src.c b/tests/fcntl-open/src.c
index 52d2e7e4..bd52dd3f 100644
--- a/tests/fcntl-open/src.c
+++ b/tests/fcntl-open/src.c
@@ -1,13 +1,45 @@
-#include <stdio.h>
+#include <assert.h>
#include <errno.h>
-#include <sys/stat.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
-int main() {
+char nonexistent_name[] = "noexist-##";
+
+void create_file(const char *path, const char *buffer, int mode) {
+ int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
+ assert(fd >= 0);
+
+ int err = write(fd, buffer, sizeof(char) * strlen(buffer));
+ assert(err == (sizeof(char) * strlen(buffer)));
+
+ close(fd);
+}
+
+void setup() {
+ create_file("test-file", "abcdef", 0777);
+ mkdir("test-folder", 0777);
+}
+
+void cleanup() {
+ unlink("test-file");
+ rmdir("test-folder");
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 16; j++) {
+ nonexistent_name[8] = 'a' + i;
+ nonexistent_name[9] = 'a' + j;
+ unlink(nonexistent_name);
+ }
+ }
+ unlink("creat-me");
+}
+
+void test() {
struct stat s;
int modes[] = {O_RDONLY, O_WRONLY, O_RDWR};
- char nonexistent_name[] = "/noexist-##";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 16; j++) {
@@ -18,25 +50,25 @@ int main() {
if (j & 0x8) flags |= O_APPEND;
printf("EXISTING FILE %d,%d\n", i, j);
- printf("success: %d\n", open("/test-file", flags, 0777) != -1);
+ printf("success: %d\n", open("test-file", flags, 0777) != -1);
printf("errno: %d\n", errno);
- stat("/test-file", &s);
+ stat("test-file", &s);
printf("st_mode: 0%o\n", s.st_mode & 037777777000);
memset(&s, 0, sizeof s);
printf("\n");
errno = 0;
printf("EXISTING FOLDER %d,%d\n", i, j);
- printf("success: %d\n", open("/test-folder", flags, 0777) != -1);
+ printf("success: %d\n", open("test-folder", flags, 0777) != -1);
printf("errno: %d\n", errno);
- stat("/test-folder", &s);
+ stat("test-folder", &s);
printf("st_mode: 0%o\n", s.st_mode & 037777777000);
memset(&s, 0, sizeof s);
printf("\n");
errno = 0;
- nonexistent_name[9] = 'a' + i;
- nonexistent_name[10] = 'a' + j;
+ nonexistent_name[8] = 'a' + i;
+ nonexistent_name[9] = 'a' + j;
printf("NON-EXISTING %d,%d\n", i, j);
printf("success: %d\n", open(nonexistent_name, flags, 0777) != -1);
printf("errno: %d\n", errno);
@@ -49,8 +81,14 @@ int main() {
}
printf("CREAT\n");
- printf("success: %d\n", creat("/creat-me", 0777) != -1);
+ printf("success: %d\n", creat("creat-me", 0777) != -1);
printf("errno: %d\n", errno);
-
- return 0;
}
+
+int main() {
+ atexit(cleanup);
+ signal(SIGABRT, cleanup);
+ setup();
+ test();
+ return EXIT_SUCCESS;
+} \ No newline at end of file
diff --git a/tests/runner.py b/tests/runner.py
index 96b00c50..bc0c77a4 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6831,20 +6831,9 @@ def process(filename):
self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h'])
def test_fcntl_open(self):
- add_pre_run = '''
-def process(filename):
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- \'\'\'
- FS.createDataFile('/', 'test-file', 'abcdef', true, true);
- FS.createFolder('/', 'test-folder', true, true);
- \'\'\'
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'fcntl-open', 'src.c'), 'r').read()
expected = open(path_from_root('tests', 'fcntl-open', 'output.txt'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h'])
+ self.do_run(src, expected, force_c=True, extra_emscripten_args=['-H', 'libc/fcntl.h'])
def test_fcntl_misc(self):
add_pre_run = '''