Skip to content

Commit

Permalink
Use standard file api
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 29, 2024
1 parent 5ea5ca4 commit 9af034e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/cpp/segfault-handler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <map>
#include <string>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdio.h>
Expand All @@ -24,6 +23,16 @@ namespace segfault {

char logFilePath[512] = "segfault.log";


inline bool _checkExists(const char* name) {
if (FILE *file = fopen(name, "r")) {
fclose(file);
return true;
} else {
return false;
}
}

#ifdef _WIN32
constexpr auto GETPID = _getpid;
#define SEGFAULT_HANDLER LONG CALLBACK handleSignal(PEXCEPTION_POINTERS info)
Expand Down Expand Up @@ -217,7 +226,7 @@ static inline void _writeStackTrace(std::ofstream &outfile, uint32_t signalId) {
static inline std::ofstream _openLogFile() {
std::ofstream outfile;

if (!std::filesystem::exists(logFilePath)) {
if (!_checkExists(logFilePath)) {
std::cerr
<< "SegfaultHandler: The exception won't be logged into a file"
<< ", unless 'segfault.log' exists." << std::endl;
Expand Down

0 comments on commit 9af034e

Please sign in to comment.