@@ -75,8 +75,15 @@ impl FileDesc {
7575 unsafe fn cvt_pread64 ( fd : c_int , buf : * mut c_void , count : usize , offset : i64 )
7676 -> io:: Result < isize >
7777 {
78+ use convert:: TryInto ;
7879 use libc:: pread64;
79- cvt ( pread64 ( fd, buf, count, offset as i32 ) )
80+ // pread64 on emscripten actually takes a 32 bit offset
81+ if let Ok ( o) = offset. try_into ( ) {
82+ cvt ( pread64 ( fd, buf, count, o) )
83+ } else {
84+ Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
85+ "cannot pread >2GB" ) )
86+ }
8087 }
8188
8289 #[ cfg( not( any( target_os = "android" , target_os = "emscripten" ) ) ) ]
@@ -116,8 +123,15 @@ impl FileDesc {
116123 unsafe fn cvt_pwrite64 ( fd : c_int , buf : * const c_void , count : usize , offset : i64 )
117124 -> io:: Result < isize >
118125 {
126+ use convert:: TryInto ;
119127 use libc:: pwrite64;
120- cvt ( pwrite64 ( fd, buf, count, offset as i32 ) )
128+ // pwrite64 on emscripten actually takes a 32 bit offset
129+ if let Ok ( o) = offset. try_into ( ) {
130+ cvt ( pwrite64 ( fd, buf, count, o) )
131+ } else {
132+ Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
133+ "cannot pwrite >2GB" ) )
134+ }
121135 }
122136
123137 #[ cfg( not( any( target_os = "android" , target_os = "emscripten" ) ) ) ]
0 commit comments