]> granicus.if.org Git - sysstat/commitdiff
Create a separate function to get report's date
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Mar 2017 09:44:31 +0000 (11:44 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Mar 2017 09:44:31 +0000 (11:44 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
common.c
common.h

index d6f156dab4752e2f6d39d21431f568728c577994..dfed735aa23f889bcab056ce506d628d218abaee 100644 (file)
--- a/common.c
+++ b/common.c
@@ -415,6 +415,39 @@ void xprintf(int nr_tab, const char *fmtf, ...)
        printf("%s\n", buf);
 }
 
+/*
+ ***************************************************************************
+ * Get report date as a string of characters.
+ *
+ * IN:
+ * @rectime    Date to display (don't use time fields).
+ * @cur_date   String where date will be saved.
+ * @sz         Max size of cur_date string.
+ *
+ * OUT:
+ * @cur_date   Date (string format).
+ *
+ * RETURNS:
+ * TRUE if S_TIME_FORMAT is set to ISO, or FALSE otherwise.
+ ***************************************************************************
+ */
+int set_report_date(struct tm *rectime, char cur_date[], int sz)
+{
+       if (rectime == NULL) {
+               strncpy(cur_date, "?/?/?", sz);
+               cur_date[sz - 1] = '\0';
+       }
+       else if (is_iso_time_fmt()) {
+               strftime(cur_date, sz, "%Y-%m-%d", rectime);
+               return 1;
+       }
+       else {
+               strftime(cur_date, sz, "%x", rectime);
+       }
+
+       return 0;
+}
+
 /*
  ***************************************************************************
  * Print banner.
@@ -439,16 +472,7 @@ int print_gal_header(struct tm *rectime, char *sysname, char *release,
        char cur_date[TIMESTAMP_LEN];
        int rc = 0;
 
-       if (rectime == NULL) {
-               strcpy(cur_date, "?/?/?");
-       }
-       else if (is_iso_time_fmt()) {
-               strftime(cur_date, sizeof(cur_date), "%Y-%m-%d", rectime);
-               rc = 1;
-       }
-       else {
-               strftime(cur_date, sizeof(cur_date), "%x", rectime);
-       }
+       rc = set_report_date(rectime, cur_date, sizeof(cur_date));
 
        if (format == PLAIN_OUTPUT) {
                /* Plain output */
index 04226a365466cc74e866011982da639c07711ed7..70736f75a93d3ea3810e81dc73bb03695617ec05 100644 (file)
--- a/common.h
+++ b/common.h
@@ -284,6 +284,8 @@ int print_gal_header
        (struct tm *, char *, char *, char *, char *, int, int);
 void print_version
        (void);
+int set_report_date
+       (struct tm *, char[], int);
 char *strtolower
        (char *);
 void sysstat_panic