diff --git a/AUTHORS b/AUTHORS index 5604388d3d2d0..43e4110e2ac0b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -271,3 +271,4 @@ a license to everyone to use it as detailed in LICENSE.) * Vladimir Davidovich * Christophe Gragnic * Murphy McCauley +* Anatoly Trosinenko diff --git a/src/library_syscall.js b/src/library_syscall.js index f5de05907d17f..8b551c6e9f1dd 100644 --- a/src/library_syscall.js +++ b/src/library_syscall.js @@ -838,11 +838,8 @@ var SyscallsLibrary = { return FS.read(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, count, offset); }, __syscall181: function(which, varargs) { // pwrite64 -#if SYSCALL_DEBUG - Module.printErr('warning: untested syscall'); -#endif var stream = SYSCALLS.getStreamFromFD(), buf = SYSCALLS.get(), count = SYSCALLS.get(), zero = SYSCALLS.getZero(), offset = SYSCALLS.get64(); - return FS.write(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, nbyte, offset); + return FS.write(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, count, offset); }, __syscall183: function(which, varargs) { // getcwd var buf = SYSCALLS.get(), size = SYSCALLS.get(); diff --git a/tests/unistd/io.c b/tests/unistd/io.c index 3c22133095cf8..7a1e166b04e0e 100644 --- a/tests/unistd/io.c +++ b/tests/unistd/io.c @@ -156,6 +156,16 @@ int main() { printf("errno: %d\n\n", errno); errno = 0; + printf("pwrite to the middle of file: %d\n", pwrite(f, writeBuffer + 2, 3, 17)); + printf("errno: %d\n", errno); + printf("seek: %d\n\n", lseek(f, 0, SEEK_CUR)); + errno = 0; + + printf("pwrite past end of file: %d\n", pwrite(f, writeBuffer, 5, 32)); + printf("errno: %d\n", errno); + printf("seek: %d\n\n", lseek(f, 0, SEEK_CUR)); + errno = 0; + int bytesRead; printf("seek: %d\n", lseek(f, 0, SEEK_SET)); printf("read after write: %d\n", bytesRead = read(f, readBuffer, sizeof readBuffer)); diff --git a/tests/unistd/io.out b/tests/unistd/io.out index c979557e023c8..79713b103fa00 100644 --- a/tests/unistd/io.out +++ b/tests/unistd/io.out @@ -66,7 +66,15 @@ seek: 23 write after end of file: 8 errno: 0 +pwrite to the middle of file: 3 +errno: 0 +seek: 31 + +pwrite past end of file: 5 +errno: 0 +seek: 31 + seek: 0 -read after write: 31 +read after write: 37 errno: 0 -final: wri4567890wri\0\0\0\0\0\0\0\0\0\0writeme\0 +final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write