summaryrefslogtreecommitdiff
path: root/src/session-initialize-bincimap-up.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/session-initialize-bincimap-up.cc')
-rw-r--r--src/session-initialize-bincimap-up.cc54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/session-initialize-bincimap-up.cc b/src/session-initialize-bincimap-up.cc
index 646315a..ee9f8db 100644
--- a/src/session-initialize-bincimap-up.cc
+++ b/src/session-initialize-bincimap-up.cc
@@ -11,16 +11,17 @@
#include "iodevice.h"
#include "iofactory.h"
#include "multilogdevice.h"
+#include "operators.h"
#include "session.h"
#include "stdiodevice.h"
#include "syslogdevice.h"
#include "tools.h"
+#include <cctype>
+#include <charconv>
#include <map>
#include <string>
-#include <ctype.h>
-
#include <fcntl.h>
#include <syslog.h>
@@ -71,30 +72,31 @@ bool Session::initialize(int argc, char *argv[])
ioFactory.addDevice(device);
} else if (logtype == "syslog") {
const string f = session.getEnv("SYSLOG_FACILITY");
- int facility;
-
- if (isdigit(f[0]))
- facility = atoi(f);
- else if (f == "LOG_USER")
- facility = LOG_USER;
- else if (f == "LOG_LOCAL0")
- facility = LOG_LOCAL0;
- else if (f == "LOG_LOCAL1")
- facility = LOG_LOCAL1;
- else if (f == "LOG_LOCAL2")
- facility = LOG_LOCAL2;
- else if (f == "LOG_LOCAL3")
- facility = LOG_LOCAL3;
- else if (f == "LOG_LOCAL4")
- facility = LOG_LOCAL4;
- else if (f == "LOG_LOCAL5")
- facility = LOG_LOCAL5;
- else if (f == "LOG_LOCAL6")
- facility = LOG_LOCAL6;
- else if (f == "LOG_LOCAL7")
- facility = LOG_LOCAL7;
- else
- facility = LOG_DAEMON;
+ int facility = 0;
+ auto fcr = std::from_chars(f.c_str(), f.c_str() + f.size(), facility);
+
+ if (fcr.ec != std::errc{}) {
+ if (f == "LOG_USER")
+ facility = LOG_USER;
+ else if (f == "LOG_LOCAL0")
+ facility = LOG_LOCAL0;
+ else if (f == "LOG_LOCAL1")
+ facility = LOG_LOCAL1;
+ else if (f == "LOG_LOCAL2")
+ facility = LOG_LOCAL2;
+ else if (f == "LOG_LOCAL3")
+ facility = LOG_LOCAL3;
+ else if (f == "LOG_LOCAL4")
+ facility = LOG_LOCAL4;
+ else if (f == "LOG_LOCAL5")
+ facility = LOG_LOCAL5;
+ else if (f == "LOG_LOCAL6")
+ facility = LOG_LOCAL6;
+ else if (f == "LOG_LOCAL7")
+ facility = LOG_LOCAL7;
+ else
+ facility = LOG_DAEMON;
+ }
SyslogDevice *device = new SyslogDevice(IODevice::IsEnabled | IODevice::FlushesOnEndl,
"bincimap-up",