| 820 | } |
| 821 | |
| 822 | void ShrinkDebugFile() { |
| 823 | // Scroll debug.log if it's getting too big |
| 824 | boost::filesystem::path pathLog = GetDataDir() / "debug.log"; |
| 825 | FILE* file = fopen(pathLog.string().c_str(), "r"); |
| 826 | if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000) { |
| 827 | // Restart the file with some of the end |
| 828 | char pch[200000]; |
| 829 | fseek(file, -sizeof(pch), SEEK_END); |
| 830 | int nBytes = fread(pch, 1, sizeof(pch), file); |
| 831 | fclose(file); |
| 832 | |
| 833 | file = fopen(pathLog.string().c_str(), "w"); |
| 834 | if (file) { |
| 835 | fwrite(pch, 1, nBytes, file); |
| 836 | fclose(file); |
| 837 | } |
| 838 | } else if (file != NULL) |
| 839 | fclose(file); |
| 840 | } |
| 841 | |
| 842 | // |
| 843 | // "Never go to sea with two chronometers; take one or three." |