Clean-up: time: change space to tabs
[lttng-tools.git] / src / common / time.c
index 885f58cb175bf4a2336cf957047abcc339642c15..d084a3fddbdb5c462e5246fb83b9c336c4b898e9 100644 (file)
@@ -1,21 +1,12 @@
 /*
- * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <common/time.h>
+#include <common/error.h>
 #include <common/macros.h>
 #include <common/error.h>
 #include <stddef.h>
@@ -97,7 +88,7 @@ int time_to_iso8601_str(time_t time, char *str, size_t len)
                goto end;
        }
 
-        tm_result = localtime_r(&time, &tm_storage);
+       tm_result = localtime_r(&time, &tm_storage);
        if (!tm_result) {
                ret = -1;
                PERROR("Failed to break down timestamp to tm structure");
@@ -113,3 +104,35 @@ int time_to_iso8601_str(time_t time, char *str, size_t len)
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int time_to_datetime_str(time_t time, char *str, size_t len)
+{
+       int ret = 0;
+       struct tm *tm_result;
+       struct tm tm_storage;
+       size_t strf_ret;
+
+       if (len < DATETIME_STR_LEN) {
+               ERR("Buffer too short to format to datetime: %zu bytes provided when at least %zu are needed",
+                               len, DATETIME_STR_LEN);
+               ret = -1;
+               goto end;
+       }
+
+       tm_result = localtime_r(&time, &tm_storage);
+       if (!tm_result) {
+               ret = -1;
+               PERROR("Failed to break down timestamp to tm structure");
+               goto end;
+       }
+
+       strf_ret = strftime(str, len, "%Y%m%d-%H%M%S", tm_result);
+       if (strf_ret == 0) {
+               ret = -1;
+               ERR("Failed to format timestamp as local time");
+               goto end;
+       }
+end:
+       return ret;
+}
This page took 0.02353 seconds and 4 git commands to generate.