| 16 | } |
| 17 | |
| 18 | int FHistory::Load(void) { |
| 19 | if (!fname.empty()) { |
| 20 | FILE *f; |
| 21 | #ifdef _WIN32 |
| 22 | errno_t e; |
| 23 | e = fopen_s(&f, fname.c_str(), "r"); |
| 24 | #else |
| 25 | f = fopen(fname.c_str(), "r"); |
| 26 | #endif |
| 27 | |
| 28 | count = 0; |
| 29 | if (!f) return 0; |
| 30 | |
| 31 | while (count < FHISTORY_COUNT_MAX) { |
| 32 | char *r; |
| 33 | |
| 34 | r = fgets(history[count], FHISTORY_FNAME_LEN_MAX, f); |
| 35 | if (r) { |
| 36 | count++; |
| 37 | |
| 38 | /// strip off the trailing line break |
| 39 | while (*r) { |
| 40 | if ((*r == '\r') || (*r == '\n')) { |
| 41 | *r = '\0'; |
| 42 | break; |
| 43 | } |
| 44 | r++; |
| 45 | } |
| 46 | |
| 47 | } else { |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | fclose(f); |
| 52 | } else { |
| 53 | return -1; |
| 54 | } |
| 55 | |
| 56 | return count; |
| 57 | } |
| 58 | |
| 59 | int FHistory::Prepend_save(const std::string &newfile) { |
| 60 | if (!fname.empty()) { |
no outgoing calls
no test coverage detected