summaryrefslogtreecommitdiffstats
path: root/common/sys/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/sys/log.c')
-rw-r--r--common/sys/log.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/common/sys/log.c b/common/sys/log.c
new file mode 100644
index 00000000..9fe3d514
--- /dev/null
+++ b/common/sys/log.c
@@ -0,0 +1,43 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "libbbsutil.h"
+
+int
+log_filef(const char *fn, int log_flag, const char *fmt,...)
+{
+ char msg[256];
+
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(msg, sizeof(msg), fmt, ap);
+ va_end(ap);
+
+ return log_file(fn, log_flag, msg);
+}
+
+int
+log_file(const char *fn, int log_flag, const char *msg)
+{
+ int fd;
+ int flag = O_APPEND | O_WRONLY;
+ int mode = 0664;
+
+ if (log_flag & LOG_CREAT)
+ flag |= O_CREAT;
+
+ fd = open(fn, flag, mode);
+ if( fd < 0 )
+ return -1;
+
+ if( write(fd, msg, strlen(msg)) < 0 ){
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+