| 368 | |
| 369 | |
| 370 | int File::Read(void *Data,size_t Size) |
| 371 | { |
| 372 | int64 FilePos=0; // Initialized only to suppress some compilers warning. |
| 373 | |
| 374 | if (IgnoreReadErrors) |
| 375 | FilePos=Tell(); |
| 376 | int ReadSize; |
| 377 | while (true) |
| 378 | { |
| 379 | ReadSize=DirectRead(Data,Size); |
| 380 | if (ReadSize==-1) |
| 381 | { |
| 382 | ErrorType=FILE_READERROR; |
| 383 | if (AllowExceptions) |
| 384 | if (IgnoreReadErrors) |
| 385 | { |
| 386 | ReadSize=0; |
| 387 | for (size_t I=0;I<Size;I+=512) |
| 388 | { |
| 389 | Seek(FilePos+I,SEEK_SET); |
| 390 | size_t SizeToRead=Min(Size-I,512); |
| 391 | int ReadCode=DirectRead(Data,SizeToRead); |
| 392 | ReadSize+=(ReadCode==-1) ? 512:ReadCode; |
| 393 | } |
| 394 | } |
| 395 | else |
| 396 | { |
| 397 | if (HandleType==FILE_HANDLENORMAL && ErrHandler.AskRepeatRead(FileName)) |
| 398 | continue; |
| 399 | ErrHandler.ReadError(FileName); |
| 400 | } |
| 401 | } |
| 402 | break; |
| 403 | } |
| 404 | return ReadSize; // It can return -1 only if AllowExceptions is disabled. |
| 405 | } |
| 406 | |
| 407 | |
| 408 | // Returns -1 in case of error. |
no test coverage detected