diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-26 23:49:36 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-26 23:57:55 +0000 |
commit | eb658f87a3a53e7ad2f5815d498aceb9a974dd5e (patch) | |
tree | a70db0968060b4382dd2881777c8a0e3c742dbfe /src/init.cpp | |
parent | 1e87849e5c218cc3d99e259f9ea43493bd8bc633 (diff) |
Use fstream for accessing files where possible.
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/init.cpp b/src/init.cpp index aa6ff1336..b974f7cdd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -217,19 +217,12 @@ static void remove_pidfile() static void write_pidfile() { - FILE *pidfile = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("pid").c_str(), "w"); - if (pidfile) - { -#ifdef _WIN32 - fprintf(pidfile, "%d\n", static_cast<int>(GetCurrentProcessId())); -#else - fprintf(pidfile, "%d\n", static_cast<int>(getpid())); -#endif - fclose(pidfile); - atexit(remove_pidfile); - } - else - throw CoreException("Can not write to PID file " + Config->GetBlock("serverinfo")->Get<const Anope::string>("pid")); + const auto pidfile = Config->GetBlock("serverinfo")->Get<const Anope::string>("pid"); + std::ofstream stream(pidfile.str()); + if (!stream.is_open()) + throw CoreException("Can not write to PID file " + pidfile); + stream << getpid() << std::endl; + atexit(remove_pidfile); } static void setuidgid() |