aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_fs.js2
-rw-r--r--tests/unistd/io.c13
-rw-r--r--tests/unistd/io.js2
-rw-r--r--tests/unistd/io.out5
4 files changed, 21 insertions, 1 deletions
diff --git a/src/library_fs.js b/src/library_fs.js
index 9c8223ab..63ad7c8d 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -530,7 +530,7 @@ mergeInto(LibraryManager.library, {
},
createDevice: function(parent, name, input, output) {
var path = PATH.join(typeof parent === 'string' ? parent : FS.getPath(parent), name);
- var mode = input && output ? 0777 : (input ? 0333 : 0555);
+ var mode = FS.getMode(!!input, !!output);
if (!FS.createDevice.major) FS.createDevice.major = 64;
var dev = FS.makedev(FS.createDevice.major++, 0);
// Create a fake device that a set of stream ops to emulate
diff --git a/tests/unistd/io.c b/tests/unistd/io.c
index eeb80373..a96290ef 100644
--- a/tests/unistd/io.c
+++ b/tests/unistd/io.c
@@ -34,6 +34,19 @@ int main() {
printf("errno: %d\n\n", errno);
errno = 0;
+ int cd_ro_r = open("/createDevice-read-only", O_RDONLY);
+ printf("open read-only device from createDevice for read, errno: %d\n", errno);
+ errno = 0;
+ int cd_ro_w = open("/createDevice-read-only", O_WRONLY);
+ printf("open read-only device from createDevice for write, errno: %d\n", errno);
+ errno = 0;
+ int cd_wo_r = open("/createDevice-write-only", O_RDONLY);
+ printf("open write-only device from createDevice for read, errno: %d\n", errno);
+ errno = 0;
+ int cd_wo_w = open("/createDevice-write-only", O_WRONLY);
+ printf("open write-only device from createDevice for write, errno: %d\n\n", errno);
+ errno = 0;
+
int f = open("/file", O_RDWR);
printf("read from file: %d\n", read(f, readBuffer, sizeof readBuffer));
printf("data: %s\n", readBuffer);
diff --git a/tests/unistd/io.js b/tests/unistd/io.js
index e2e442ec..cf66a438 100644
--- a/tests/unistd/io.js
+++ b/tests/unistd/io.js
@@ -14,6 +14,8 @@
}, function(arg) {
throw new Error('Broken device output.');
});
+ FS.createDevice('/', 'createDevice-read-only', function() {});
+ FS.createDevice('/', 'createDevice-write-only', null, function() {});
FS.createDataFile('/', 'file', '1234567890', true, true);
FS.createFolder('/', 'folder', true, true);
})();
diff --git a/tests/unistd/io.out b/tests/unistd/io.out
index 3061b94e..037d0c34 100644
--- a/tests/unistd/io.out
+++ b/tests/unistd/io.out
@@ -22,6 +22,11 @@ TO DEVICE: 0
write to device: 8
errno: 0
+open read-only device from createDevice for read, errno: 0
+open read-only device from createDevice for write, errno: 13
+open write-only device from createDevice for read, errno: 13
+open write-only device from createDevice for write, errno: 0
+
read from file: 10
data: 1234567890
errno: 0