@@ -21,7 +21,7 @@ use str;
21
21
use result:: * ;
22
22
use rt:: io:: IoError ;
23
23
use rt:: io:: net:: ip:: { SocketAddr , IpAddr } ;
24
- use rt:: io:: { standard_error, OtherIoError } ;
24
+ use rt:: io:: { standard_error, OtherIoError , SeekStyle , SeekSet , SeekCur , SeekEnd } ;
25
25
use rt:: local:: Local ;
26
26
use rt:: rtio:: * ;
27
27
use rt:: sched:: { Scheduler , SchedHandle } ;
@@ -31,7 +31,7 @@ use rt::uv::idle::IdleWatcher;
31
31
use rt:: uv:: net:: { UvIpv4SocketAddr , UvIpv6SocketAddr } ;
32
32
use unstable:: sync:: Exclusive ;
33
33
use super :: super :: io:: support:: PathLike ;
34
- use libc:: { lseek, c_long, SEEK_CUR } ;
34
+ use libc:: { lseek, c_long} ;
35
35
36
36
#[ cfg( test) ] use container:: Container ;
37
37
#[ cfg( test) ] use unstable:: run_in_bare_thread;
@@ -1122,6 +1122,22 @@ impl UvFileStream {
1122
1122
} ;
1123
1123
result_cell. take ( )
1124
1124
}
1125
+ fn seek_common ( & mut self , pos : i64 , whence : c_int ) ->
1126
+ Result < u64 , IoError > {
1127
+ #[ fixed_stack_segment] ; #[ inline( never) ] ;
1128
+ unsafe {
1129
+ match lseek ( ( * self . fd ) , pos as c_long , whence) {
1130
+ -1 => {
1131
+ Err ( IoError {
1132
+ kind : OtherIoError ,
1133
+ desc : "Failed to lseek." ,
1134
+ detail : None
1135
+ } )
1136
+ } ,
1137
+ n => Ok ( n as u64 )
1138
+ }
1139
+ }
1140
+ }
1125
1141
}
1126
1142
1127
1143
impl Drop for UvFileStream {
@@ -1155,35 +1171,20 @@ impl RtioFileStream for UvFileStream {
1155
1171
fn pwrite ( & mut self , buf : & [ u8 ] , offset : u64 ) -> Result < ( ) , IoError > {
1156
1172
self . base_write ( buf, offset as i64 )
1157
1173
}
1158
- fn seek ( & mut self , pos : i64 , whence : i64 ) -> Result < ( ) , IoError > {
1159
- #[ fixed_stack_segment] ; #[ inline( never) ] ;
1160
- unsafe {
1161
- match lseek ( ( * self . fd ) , pos as c_long , whence as c_int ) {
1162
- -1 => {
1163
- Err ( IoError {
1164
- kind : OtherIoError ,
1165
- desc : "Failed to lseek." ,
1166
- detail : None
1167
- } )
1168
- } ,
1169
- _ => Ok ( ( ) )
1170
- }
1171
- }
1174
+ fn seek ( & mut self , pos : i64 , whence : SeekStyle ) -> Result < u64 , IoError > {
1175
+ use libc:: { SEEK_SET , SEEK_CUR , SEEK_END } ;
1176
+ let whence = match whence {
1177
+ SeekSet => SEEK_SET ,
1178
+ SeekCur => SEEK_CUR ,
1179
+ SeekEnd => SEEK_END
1180
+ } ;
1181
+ self . seek_common ( pos, whence)
1172
1182
}
1173
1183
fn tell ( & self ) -> Result < u64 , IoError > {
1174
- #[ fixed_stack_segment] ; #[ inline( never) ] ;
1175
- unsafe {
1176
- match lseek ( ( * self . fd ) , 0 , SEEK_CUR ) {
1177
- -1 => {
1178
- Err ( IoError {
1179
- kind : OtherIoError ,
1180
- desc : "Failed to lseek, needed to tell()." ,
1181
- detail : None
1182
- } )
1183
- } ,
1184
- n=> Ok ( n as u64 )
1185
- }
1186
- }
1184
+ use libc:: SEEK_CUR ;
1185
+ // this is temporary
1186
+ let self_ = unsafe { cast:: transmute :: < & UvFileStream , & mut UvFileStream > ( self ) } ;
1187
+ self_. seek_common ( 0 , SEEK_CUR )
1187
1188
}
1188
1189
fn flush ( & mut self ) -> Result < ( ) , IoError > {
1189
1190
Ok ( ( ) )
0 commit comments