| 361 | } |
| 362 | |
| 363 | bool readLines(const std::string& filePath, bool stripNewLine, std::function<void(const char* line)> callback) { |
| 364 | auto lock = getLock(filePath)->asScopedLock(); |
| 365 | lock.lock(); |
| 366 | |
| 367 | auto* file = fopen(filePath.c_str(), "r"); |
| 368 | if (file == nullptr) { |
| 369 | return false; |
| 370 | } |
| 371 | |
| 372 | char line[1024]; |
| 373 | |
| 374 | while (fgets(line, sizeof(line), file) != nullptr) { |
| 375 | // Strip newline |
| 376 | if (stripNewLine) { |
| 377 | size_t line_length = strlen(line); |
| 378 | if (line_length > 0 && line[line_length - 1] == '\n') { |
| 379 | line[line_length - 1] = '\0'; |
| 380 | } |
| 381 | } |
| 382 | // Publish |
| 383 | callback(line); |
| 384 | } |
| 385 | |
| 386 | bool success = feof(file); |
| 387 | fclose(file); |
| 388 | return success; |
| 389 | } |
| 390 | |
| 391 | } |
no test coverage detected