aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2022-04-24 21:43:39 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2022-04-24 21:43:39 +0200
commitbde0650600ca4390978f4904e32a823c75360a0f (patch)
tree3e853ff039b6f827fbea85ec55744efd3dfb84d2
parente193f92e8394d6ae0bee73f37a65581c13edb653 (diff)
Add lprintf function
-rw-r--r--clog.c35
-rw-r--r--clog.h6
2 files changed, 41 insertions, 0 deletions
diff --git a/clog.c b/clog.c
new file mode 100644
index 0000000..b4d0dd4
--- /dev/null
+++ b/clog.c
@@ -0,0 +1,35 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "clog.h"
+
+#define TIMESTRLEN 20
+
+int lprintf(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+
+ time_t timer = time(NULL);
+ struct tm *tm_info = localtime(&timer);
+
+ char buf[TIMESTRLEN];
+ strftime(buf, TIMESTRLEN, "%Y/%m/%d %H:%M:%S", tm_info);
+ free(tm_info);
+
+ int n = printf("%s ", buf);
+
+ size_t fmtlen = strlen(format) + 2;
+ char fmt[fmtlen];
+
+ memset(fmt, '\0', fmtlen);
+ strcpy(fmt, format);
+ strcat(fmt, "\n");
+
+ n += vprintf(format, ap);
+
+ va_end(ap);
+ return n;
+}
diff --git a/clog.h b/clog.h
new file mode 100644
index 0000000..50b8455
--- /dev/null
+++ b/clog.h
@@ -0,0 +1,6 @@
+#ifndef _CLOG_H_
+#define _CLOG_H_
+
+int lprintf(const char *format, ...);
+
+#endif