| 46 | virtual ~PosixSequentialFile() { fclose(file_); } |
| 47 | |
| 48 | virtual Status Read(size_t n, Slice* result, char* scratch) { |
| 49 | Status s; |
| 50 | #if __linux__ |
| 51 | size_t r = fread_unlocked(scratch, 1, n, file_); |
| 52 | #else |
| 53 | size_t r = fread(scratch, 1, n, file_); |
| 54 | #endif |
| 55 | *result = Slice(scratch, r); |
| 56 | if (r < n) { |
| 57 | if (feof(file_)) { |
| 58 | // We leave status as ok if we hit the end of the file |
| 59 | } else { |
| 60 | // A partial read with an error: return a non-ok status |
| 61 | s = Status::IOError(filename_, strerror(errno)); |
| 62 | } |
| 63 | } |
| 64 | return s; |
| 65 | } |
| 66 | |
| 67 | virtual Status Skip(uint64_t n) { |
| 68 | if (fseek(file_, n, SEEK_CUR)) { |
no test coverage detected