[libepc/libepc-1.0] example: Avoid compiler warning about non-literal strftime() format.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libepc/libepc-1.0] example: Avoid compiler warning about non-literal strftime() format.
- Date: Mon, 19 Jun 2017 19:02:41 +0000 (UTC)
commit c24d2d9f50a99e648559025b09f321c62dcda933
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jun 19 20:54:57 2017 +0200
example: Avoid compiler warning about non-literal strftime() format.
examples/simple-publisher.c | 47 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/examples/simple-publisher.c b/examples/simple-publisher.c
index 9ac301b..2ea566d 100644
--- a/examples/simple-publisher.c
+++ b/examples/simple-publisher.c
@@ -22,20 +22,55 @@
static EpcProtocol protocol = EPC_PROTOCOL_HTTPS;
static EpcContents*
-timestamp_handler (EpcPublisher *publisher G_GNUC_UNUSED,
+timestamp_handler_date (EpcPublisher *publisher G_GNUC_UNUSED,
const gchar *key G_GNUC_UNUSED,
gpointer data)
{
time_t now = time (NULL);
struct tm *tm = localtime (&now);
- const gchar *format = data;
gsize length = 60;
gchar *buffer;
/* Create custom content */
buffer = g_malloc (length);
- length = strftime (buffer, length, format, tm);
+ length = strftime (buffer, length, "%x", tm);
+
+ return epc_contents_new ("text/plain", buffer, length, g_free);
+}
+
+static EpcContents*
+timestamp_handler_time (EpcPublisher *publisher G_GNUC_UNUSED,
+ const gchar *key G_GNUC_UNUSED,
+ gpointer data)
+{
+ time_t now = time (NULL);
+ struct tm *tm = localtime (&now);
+ gsize length = 60;
+ gchar *buffer;
+
+ /* Create custom content */
+
+ buffer = g_malloc (length);
+ length = strftime (buffer, length, "%X", tm);
+
+ return epc_contents_new ("text/plain", buffer, length, g_free);
+}
+
+static EpcContents*
+timestamp_handler_date_time (EpcPublisher *publisher G_GNUC_UNUSED,
+ const gchar *key G_GNUC_UNUSED,
+ gpointer data)
+{
+ time_t now = time (NULL);
+ struct tm *tm = localtime (&now);
+ gsize length = 60;
+ gchar *buffer;
+
+ /* Create custom content */
+
+ buffer = g_malloc (length);
+ length = strftime (buffer, length, "%x %X", tm);
return epc_contents_new ("text/plain", buffer, length, g_free);
}
@@ -139,9 +174,9 @@ main (int argc,
* as no arguments are passed on the command line. */
epc_publisher_add (publisher, "test", "value", -1);
- epc_publisher_add_handler (publisher, "date", timestamp_handler, "%x", NULL);
- epc_publisher_add_handler (publisher, "time", timestamp_handler, "%X", NULL);
- epc_publisher_add_handler (publisher, "date-time", timestamp_handler, "%x %X", NULL);
+ epc_publisher_add_handler (publisher, "date", timestamp_handler_date, NULL, NULL);
+ epc_publisher_add_handler (publisher, "time", timestamp_handler_time, NULL, NULL);
+ epc_publisher_add_handler (publisher, "date-time", timestamp_handler_date_time, NULL, NULL);
epc_publisher_add (publisher, "sensitive",
"This value is top secret.", -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]