summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-02-26 23:49:36 +0000
committerSadie Powell <sadie@witchery.services>2024-02-26 23:57:55 +0000
commiteb658f87a3a53e7ad2f5815d498aceb9a974dd5e (patch)
treea70db0968060b4382dd2881777c8a0e3c742dbfe /src
parent1e87849e5c218cc3d99e259f9ea43493bd8bc633 (diff)
Use fstream for accessing files where possible.
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp19
-rw-r--r--src/messages.cpp22
2 files changed, 15 insertions, 26 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()
diff --git a/src/messages.cpp b/src/messages.cpp
index 1d2d28a89..ba9ddfbce 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -240,21 +240,17 @@ void MOTD::Run(MessageSource &source, const std::vector<Anope::string> &params,
if (s != Me)
return;
- FILE *f = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").c_str(), "r");
- if (f)
+ std::ifstream stream(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").str());
+ if (!stream.is_open())
{
- IRCD->SendNumeric(375, source.GetSource(), "- " + s->GetName() + " Message of the Day");
- char buf[BUFSIZE];
- while (fgets(buf, sizeof(buf), f))
- {
- buf[strlen(buf) - 1] = 0;
- IRCD->SendNumeric(372, source.GetSource(), Anope::printf("- %s", buf));
- }
- fclose(f);
- IRCD->SendNumeric(376, source.GetSource(), "End of /MOTD command.");
- }
- else
IRCD->SendNumeric(422, source.GetSource(), "- MOTD file not found! Please contact your IRC administrator.");
+ return;
+ }
+
+ IRCD->SendNumeric(375, source.GetSource(), "- " + s->GetName() + " Message of the Day");
+ for (Anope::string line; std::getline(stream, line.str()); )
+ IRCD->SendNumeric(372, source.GetSource(), Anope::printf("- %s", line.c_str()));
+ IRCD->SendNumeric(376, source.GetSource(), "End of /MOTD command.");
}
void Notice::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)