David Marec 9 月之前
父节点
当前提交
e6f10825c3
共有 3 个文件被更改,包括 63 次插入0 次删除
  1. 23 0
      common/Makefile
  2. 23 0
      common/libdm.c
  3. 17 0
      common/libdm.h

+ 23 - 0
common/Makefile

@@ -0,0 +1,23 @@
+CFLAGS+=-O3 -Wall -fno-strict-aliasing
+CFLAGS+=-Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough
+CFLAGS+=-Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
+CFLAGS+=-fstack-clash-protection -fstack-protector-strong
+CFLAGS+=-fstrict-flex-arrays=3 -fPIC
+
+LDFLAGS+=-shared -fpic
+
+PROJ=libdm.so
+PROJ_OBJS=libdm.o
+
+.PHONY: clean
+.MAIN: $(PROJ)
+
+$(PROJ): $(PROJ_OBJS)
+	$(CC) -o ${.TARGET} ${.ALLSRC} $(LDFLAGS) 
+
+%o: 
+	$(CC) -o ${.TARGET} -c ${.IMPSRC}
+
+clean:
+	rm -f *.o $(PROJ)
+

+ 23 - 0
common/libdm.c

@@ -0,0 +1,23 @@
+#include	<time.h>
+#include	<sys/time.h>
+#include	<stdlib.h>
+#include	<stdio.h>
+#include	<unistd.h>
+
+void printdate(FILE *fd)
+{
+	struct timespec tp;
+	char buf[64U] = "!DATE!";
+	size_t tail;
+
+	if (!clock_gettime(CLOCK_REALTIME, &tp)) {
+		tail = strftime(buf, sizeof buf, "%x %X", localtime(&tp.tv_sec));
+
+		if ((tail > 0) && (sizeof buf < tail)) {
+			snprintf(buf + tail, (sizeof buf) - tail, ".%03ld", (tp.tv_nsec / 1000000));
+		}
+	}
+
+	fprintf(fd, "%s: ", buf);
+}
+

+ 17 - 0
common/libdm.h

@@ -0,0 +1,17 @@
+
+#ifndef DM_COMMON_LIB
+#define DM_COMMON_LIB
+
+#include <stdio.h>
+
+static int verbose;
+#define PRINTF(...) {do{flockfile(stdout);fprintf(stdout,__VA_ARGS__);funlockfile(stdout);}while(0);}
+#define EPRINTF(...) {do{flockfile(stderr);fprintf(stderr,__VA_ARGS__);funlockfile(stderr);}while(0);}
+#define VPRINTF(...) {if (verbose){flockfile(stdout);fprintf(stdout,__VA_ARGS__);funlockfile(stdout);}}
+
+extern void printdate(FILE *fd);
+
+/* 
+ * export LD_LIBRARY_PATH="this dir"
+ */
+#endif