From c151f2d4c85350b51fcf24ba83b426bf699269d6 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 1 Aug 2019 17:52:46 +0200 Subject: Initial import --- common/CMakeLists.txt | 3 +++ common/config.h.in | 9 +++++++++ common/util.c | 19 +++++++++++++++++++ common/util.h | 13 +++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 common/CMakeLists.txt create mode 100644 common/config.h.in create mode 100644 common/util.c create mode 100644 common/util.h (limited to 'common') diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 0000000..8636758 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,3 @@ +file(GLOB_RECURSE SOURCES *.c) + +ADD_LIBRARY(common STATIC ${SOURCES}) diff --git a/common/config.h.in b/common/config.h.in new file mode 100644 index 0000000..2f41d8d --- /dev/null +++ b/common/config.h.in @@ -0,0 +1,9 @@ +#ifndef COMMON_CONFIG_H_ +#define COMMON_CONFIG_H_ + +#define CONFIG_DIR "@CMAKE_INSTALL_PREFIX@/etc/rocket-cli-client/" +#define CONFIG_PATH CONFIG_DIR "rocket.conf" +#define VERSION "@PROJECT_VERSION@" +#define GIT_HASH "@GIT_HASH@" + +#endif diff --git a/common/util.c b/common/util.c new file mode 100644 index 0000000..0c85325 --- /dev/null +++ b/common/util.c @@ -0,0 +1,19 @@ +#include + +#include "util.h" + +void convert_iso8601(const char *time_string, int ts_len, struct tm *tm_data) +{ + tzset(); + + char temp[64]; + memset(temp, 0, sizeof(temp)); + strncpy(temp, time_string, ts_len); + + struct tm ctime; + memset(&ctime, 0, sizeof(struct tm)); + strptime(temp, "%FT%T%z", &ctime); + + long ts = mktime(&ctime) - timezone; + localtime_r(&ts, tm_data); +} diff --git a/common/util.h b/common/util.h new file mode 100644 index 0000000..464e7dc --- /dev/null +++ b/common/util.h @@ -0,0 +1,13 @@ +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include +#include + +#ifndef UNUSED +#define UNUSED __attribute__ ((__unused__)) +#endif + +void convert_iso8601(const char *time_string, int ts_len, struct tm *tm_data); + +#endif -- cgit v1.2.3