@@ -75,8 +75,15 @@ impl FileDesc {
75
75
unsafe fn cvt_pread64 ( fd : c_int , buf : * mut c_void , count : usize , offset : i64 )
76
76
-> io:: Result < isize >
77
77
{
78
+ use convert:: TryInto ;
78
79
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
+ }
80
87
}
81
88
82
89
#[ cfg( not( any( target_os = "android" , target_os = "emscripten" ) ) ) ]
@@ -116,8 +123,15 @@ impl FileDesc {
116
123
unsafe fn cvt_pwrite64 ( fd : c_int , buf : * const c_void , count : usize , offset : i64 )
117
124
-> io:: Result < isize >
118
125
{
126
+ use convert:: TryInto ;
119
127
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
+ }
121
135
}
122
136
123
137
#[ cfg( not( any( target_os = "android" , target_os = "emscripten" ) ) ) ]
0 commit comments