#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
+#include <unistd.h>
#include <string>
#include <vector>
using namespace std;
// Yes, it's a bit ugly.
-#define SYSLOG_FAKE_FILE (static_cast<FILE *>(NULL))
+#define SYSLOG_FAKE_FILE (static_cast<FILE *>(nullptr))
bool logging_started = false;
vector<FILE *> log_destinations;
void add_log_destination_file(const string &filename)
{
- FILE *fp = fopen(filename.c_str(), "a");
- if (fp == NULL) {
+ FILE *fp = fopen(filename.c_str(), "ae");
+ if (fp == nullptr) {
perror(filename.c_str());
return;
}
vsnprintf(formatted_msg, sizeof(formatted_msg), fmt, ap);
va_end(ap);
- time_t now = time(NULL);
+ time_t now = time(nullptr);
struct tm lt;
struct tm *ltime = localtime_r(&now, <);
char timestamp[1024];
- if (ltime == NULL) {
+ if (ltime == nullptr) {
strcpy(timestamp, "???");
} else {
strftime(timestamp, sizeof(timestamp), "%a, %d %b %Y %T %z", ltime);