@@ -236,8 +236,7 @@ use os;
236
236
use boxed:: Box ;
237
237
use result:: { Ok , Err , Result } ;
238
238
use rt:: rtio;
239
- use slice:: { AsSlice , SlicePrelude } ;
240
- use str:: { Str , StrPrelude } ;
239
+ use sys;
241
240
use str;
242
241
use string:: String ;
243
242
use uint;
@@ -312,91 +311,10 @@ impl IoError {
312
311
/// struct is filled with an allocated string describing the error
313
312
/// in more detail, retrieved from the operating system.
314
313
pub fn from_errno ( errno : uint , detail : bool ) -> IoError {
315
-
316
- #[ cfg( windows) ]
317
- fn get_err ( errno : i32 ) -> ( IoErrorKind , & ' static str ) {
318
- match errno {
319
- libc:: EOF => ( EndOfFile , "end of file" ) ,
320
- libc:: ERROR_NO_DATA => ( BrokenPipe , "the pipe is being closed" ) ,
321
- libc:: ERROR_FILE_NOT_FOUND => ( FileNotFound , "file not found" ) ,
322
- libc:: ERROR_INVALID_NAME => ( InvalidInput , "invalid file name" ) ,
323
- libc:: WSAECONNREFUSED => ( ConnectionRefused , "connection refused" ) ,
324
- libc:: WSAECONNRESET => ( ConnectionReset , "connection reset" ) ,
325
- libc:: ERROR_ACCESS_DENIED | libc:: WSAEACCES =>
326
- ( PermissionDenied , "permission denied" ) ,
327
- libc:: WSAEWOULDBLOCK => {
328
- ( ResourceUnavailable , "resource temporarily unavailable" )
329
- }
330
- libc:: WSAENOTCONN => ( NotConnected , "not connected" ) ,
331
- libc:: WSAECONNABORTED => ( ConnectionAborted , "connection aborted" ) ,
332
- libc:: WSAEADDRNOTAVAIL => ( ConnectionRefused , "address not available" ) ,
333
- libc:: WSAEADDRINUSE => ( ConnectionRefused , "address in use" ) ,
334
- libc:: ERROR_BROKEN_PIPE => ( EndOfFile , "the pipe has ended" ) ,
335
- libc:: ERROR_OPERATION_ABORTED =>
336
- ( TimedOut , "operation timed out" ) ,
337
- libc:: WSAEINVAL => ( InvalidInput , "invalid argument" ) ,
338
- libc:: ERROR_CALL_NOT_IMPLEMENTED =>
339
- ( IoUnavailable , "function not implemented" ) ,
340
- libc:: ERROR_INVALID_HANDLE =>
341
- ( MismatchedFileTypeForOperation ,
342
- "invalid handle provided to function" ) ,
343
- libc:: ERROR_NOTHING_TO_TERMINATE =>
344
- ( InvalidInput , "no process to kill" ) ,
345
-
346
- // libuv maps this error code to EISDIR. we do too. if it is found
347
- // to be incorrect, we can add in some more machinery to only
348
- // return this message when ERROR_INVALID_FUNCTION after certain
349
- // Windows calls.
350
- libc:: ERROR_INVALID_FUNCTION => ( InvalidInput ,
351
- "illegal operation on a directory" ) ,
352
-
353
- _ => ( OtherIoError , "unknown error" )
354
- }
355
- }
356
-
357
- #[ cfg( not( windows) ) ]
358
- fn get_err ( errno : i32 ) -> ( IoErrorKind , & ' static str ) {
359
- // FIXME: this should probably be a bit more descriptive...
360
- match errno {
361
- libc:: EOF => ( EndOfFile , "end of file" ) ,
362
- libc:: ECONNREFUSED => ( ConnectionRefused , "connection refused" ) ,
363
- libc:: ECONNRESET => ( ConnectionReset , "connection reset" ) ,
364
- libc:: EPERM | libc:: EACCES =>
365
- ( PermissionDenied , "permission denied" ) ,
366
- libc:: EPIPE => ( BrokenPipe , "broken pipe" ) ,
367
- libc:: ENOTCONN => ( NotConnected , "not connected" ) ,
368
- libc:: ECONNABORTED => ( ConnectionAborted , "connection aborted" ) ,
369
- libc:: EADDRNOTAVAIL => ( ConnectionRefused , "address not available" ) ,
370
- libc:: EADDRINUSE => ( ConnectionRefused , "address in use" ) ,
371
- libc:: ENOENT => ( FileNotFound , "no such file or directory" ) ,
372
- libc:: EISDIR => ( InvalidInput , "illegal operation on a directory" ) ,
373
- libc:: ENOSYS => ( IoUnavailable , "function not implemented" ) ,
374
- libc:: EINVAL => ( InvalidInput , "invalid argument" ) ,
375
- libc:: ENOTTY =>
376
- ( MismatchedFileTypeForOperation ,
377
- "file descriptor is not a TTY" ) ,
378
- libc:: ETIMEDOUT => ( TimedOut , "operation timed out" ) ,
379
- libc:: ECANCELED => ( TimedOut , "operation aborted" ) ,
380
-
381
- // These two constants can have the same value on some systems,
382
- // but different values on others, so we can't use a match
383
- // clause
384
- x if x == libc:: EAGAIN || x == libc:: EWOULDBLOCK =>
385
- ( ResourceUnavailable , "resource temporarily unavailable" ) ,
386
-
387
- _ => ( OtherIoError , "unknown error" )
388
- }
389
- }
390
-
391
- let ( kind, desc) = get_err ( errno as i32 ) ;
392
- IoError {
393
- kind : kind,
394
- desc : desc,
395
- detail : if detail && kind == OtherIoError {
396
- Some ( os:: error_string ( errno) . as_slice ( ) . chars ( ) . map ( |c| c. to_lowercase ( ) ) . collect ( ) )
397
- } else {
398
- None
399
- } ,
314
+ let mut err = sys:: decode_error ( errno as i32 ) ;
315
+ if detail && err. kind == OtherIoError {
316
+ err. detail = Some ( os:: error_string ( errno) . as_slice ( ) . chars ( )
317
+ . map ( |c| c. to_lowercase ( ) ) . collect ( ) )
400
318
}
401
319
}
402
320
0 commit comments