Returns the number of bytes read or -1 if the read process failed
| 381 | |
| 382 | // Returns the number of bytes read or -1 if the read process failed |
| 383 | int FileStore::Read(char *_ecv_array extBuf, size_t nBytes) noexcept |
| 384 | { |
| 385 | switch (usageMode) |
| 386 | { |
| 387 | case FileUseMode::free: |
| 388 | REPORT_INTERNAL_ERROR; |
| 389 | return -1; |
| 390 | |
| 391 | case FileUseMode::readOnly: |
| 392 | case FileUseMode::readWrite: |
| 393 | #if HAS_SBC_INTERFACE |
| 394 | if (reprap.UsingSbcInterface()) |
| 395 | { |
| 396 | int bytesRead = reprap.GetSbcInterface().ReadFile(handle, extBuf, nBytes); |
| 397 | if (bytesRead > 0) |
| 398 | { |
| 399 | offset += bytesRead; |
| 400 | } |
| 401 | return bytesRead; |
| 402 | } |
| 403 | #endif |
| 404 | #if HAS_MASS_STORAGE |
| 405 | { |
| 406 | UINT bytes_read; |
| 407 | const FRESULT readStatus = f_read(&file, extBuf, nBytes, &bytes_read); |
| 408 | if (readStatus != FR_OK) |
| 409 | { |
| 410 | reprap.GetPlatform().MessageF(ErrorMessage, "Cannot read file, error code %d\n", (int)readStatus); |
| 411 | return -1; |
| 412 | } |
| 413 | return (int)bytes_read; |
| 414 | } |
| 415 | #elif HAS_EMBEDDED_FILES |
| 416 | { |
| 417 | const int ret = EmbeddedFiles::Read(fileIndex, offset, extBuf, nBytes); |
| 418 | if (ret > 0) |
| 419 | { |
| 420 | offset += ret; |
| 421 | } |
| 422 | return ret; |
| 423 | } |
| 424 | #else |
| 425 | return -1; |
| 426 | #endif |
| 427 | |
| 428 | case FileUseMode::invalidated: |
| 429 | default: |
| 430 | return -1; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | // As Read but stop after '\n' or '\r\n' and null-terminate the string. |
| 435 | // If the next line is too long to fit in the buffer then the line will be split. |
no test coverage detected