libbb: introduce and use strftime_[YYYYMMDD]HHMMSS()
function old new delta strftime_fmt - 53 +53 strftime_YYYYMMDDHHMMSS - 12 +12 strftime_HHMMSS - 12 +12 human_time 44 43 -1 fmtstr_t 9 - -9 step_time 361 345 -16 watch_main 261 232 -29 ------------------------------------------------------------------------------ (add/remove: 3/1 grow/shrink: 0/3 up/down: 77/-55) Total: 22 bytes text data bss dec hex filename 919203 932 17692 937827 e4f63 busybox_old 919209 932 17692 937833 e4f69 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
21
libbb/time.c
21
libbb/time.c
@@ -187,6 +187,27 @@ time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *ptm)
|
||||
return t;
|
||||
}
|
||||
|
||||
static char* strftime_fmt(char *buf, unsigned len, time_t *tp, const char *fmt)
|
||||
{
|
||||
time_t t;
|
||||
if (!tp) {
|
||||
tp = &t;
|
||||
time(tp);
|
||||
}
|
||||
/* Returns pointer to NUL */
|
||||
return buf + strftime(buf, len, fmt, localtime(tp));
|
||||
}
|
||||
|
||||
char* FAST_FUNC strftime_HHMMSS(char *buf, unsigned len, time_t *tp)
|
||||
{
|
||||
return strftime_fmt(buf, len, tp, "%H:%M:%S");
|
||||
}
|
||||
|
||||
char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
|
||||
{
|
||||
return strftime_fmt(buf, len, tp, "%Y-%m-%d %H:%M:%S");
|
||||
}
|
||||
|
||||
#if ENABLE_MONOTONIC_SYSCALL
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
Reference in New Issue
Block a user