* see C11 §6.5.2.5, and
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
#define FORMAT_TIMESTAMP(t) format_timestamp((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t)
+#define FORMAT_TIMESTAMP_RELATIVE(t) \
+ format_timestamp_relative((char[FORMAT_TIMESTAMP_RELATIVE_MAX]){}, FORMAT_TIMESTAMP_RELATIVE_MAX, t)
#define FORMAT_TIMESPAN(t, accuracy) format_timespan((char[FORMAT_TIMESPAN_MAX]){}, FORMAT_TIMESPAN_MAX, t, accuracy)
+
int parse_timestamp(const char *t, usec_t *usec);
int parse_sec(const char *t, usec_t *usec);
usec_t u;
r = safe_atou64(timestamp, &u);
- if (r >= 0) {
- char relative[FORMAT_TIMESPAN_MAX];
+ if (r >= 0)
+ fprintf(file, " Timestamp: %s (%s)\n",
+ FORMAT_TIMESTAMP(u), FORMAT_TIMESTAMP_RELATIVE(u));
- fprintf(file,
- " Timestamp: %s (%s)\n",
- FORMAT_TIMESTAMP(u),
- format_timestamp_relative(relative, sizeof(relative), u));
-
- } else
+ else
fprintf(file, " Timestamp: %s\n", timestamp);
}
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
const char *s1, *s2;
SessionStatusInfo i = {};
int r;
else
printf("%"PRIu32"\n", i.uid);
- s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
if (s1)
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
const char *s1, *s2;
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
int r;
else
printf("%"PRIu32"\n", i.uid);
- s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
if (s1)
}
static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
_cleanup_free_ char *addresses = NULL;
const char *s1, *s2;
int ifi = -1;
else
putchar('\n');
- s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp.realtime);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime);
s2 = FORMAT_TIMESTAMP(i->timestamp.realtime);
if (s1)
} ImageStatusInfo;
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
- char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX];
char bs[FORMAT_BYTES_MAX];
char bs_exclusive[FORMAT_BYTES_MAX];
const char *s1, *s2, *s3, *s4;
i->read_only ? "read-only" : "writable",
i->read_only ? ansi_normal() : "");
- s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->crtime);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i->crtime);
s2 = FORMAT_TIMESTAMP(i->crtime);
if (s1 && s2)
printf("\t Created: %s; %s\n", s2, s1);
else if (s2)
printf("\t Created: %s\n", s2);
- s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->mtime);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i->mtime);
s2 = FORMAT_TIMESTAMP(i->mtime);
if (s1 && s2)
printf("\tModified: %s; %s\n", s2, s1);
UnitStatusInfo *i,
bool *ellipsized) {
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
const char *s1, *s2, *active_on, *active_off, *on, *off, *ss, *fs;
_cleanup_free_ char *formatted_path = NULL;
ExecStatusInfo *p;
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
i->active_exit_timestamp;
- s1 = format_timestamp_relative(since1, sizeof(since1), timestamp);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(timestamp);
s2 = format_timestamp_style(since2, sizeof(since2), timestamp, arg_timestamp_style);
if (s1)
}
if (endswith(i->id, ".timer")) {
- char tstamp1[FORMAT_TIMESTAMP_RELATIVE_MAX],
- tstamp2[FORMAT_TIMESTAMP_MAX];
+ char tstamp2[FORMAT_TIMESTAMP_MAX];
const char *next_rel_time, *next_time;
dual_timestamp nw, next = {i->next_elapse_real,
i->next_elapse_monotonic};
dual_timestamp_get(&nw);
next_elapse = calc_next_elapse(&nw, &next);
- next_rel_time = format_timestamp_relative(tstamp1, sizeof tstamp1, next_elapse);
+ next_rel_time = FORMAT_TIMESTAMP_RELATIVE(next_elapse);
next_time = format_timestamp_style(tstamp2, sizeof tstamp2, next_elapse, arg_timestamp_style);
if (next_time && next_rel_time)
UnitCondition *c;
int n = 0;
- s1 = format_timestamp_relative(since1, sizeof(since1), i->condition_timestamp);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp);
s2 = format_timestamp_style(since2, sizeof(since2), i->condition_timestamp, arg_timestamp_style);
printf(" Condition: start %scondition failed%s at %s%s%s\n",
}
if (!i->assert_result && i->assert_timestamp > 0) {
- s1 = format_timestamp_relative(since1, sizeof(since1), i->assert_timestamp);
+ s1 = FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp);
s2 = format_timestamp_style(since2, sizeof(since2), i->assert_timestamp, arg_timestamp_style);
printf(" Assert: start %sassertion failed%s at %s%s%s\n",
}
static int show_system_status(sd_bus *bus) {
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(machine_info_clear) struct machine_info mi = {};
_cleanup_free_ char *hn = NULL;
printf(" Since: %s; %s\n",
format_timestamp_style(since2, sizeof(since2), mi.timestamp, arg_timestamp_style),
- format_timestamp_relative(since1, sizeof(since1), mi.timestamp));
+ FORMAT_TIMESTAMP_RELATIVE(mi.timestamp));
printf(" CGroup: %s\n", mi.control_group ?: "/");
if (IN_SET(arg_transport,