aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-29 12:30:33 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-29 12:30:33 +0100
commit8f2cb7ab26b9c720c24cdeffb624bfe0c2352353 (patch)
tree8d76825f24632d338118919b0553f542fdd3a8aa /libbb
parent6c852bfcadd78f53ec7a5f35882636a2a4a66eb0 (diff)
downloadbusybox-w32-8f2cb7ab26b9c720c24cdeffb624bfe0c2352353.tar.gz
busybox-w32-8f2cb7ab26b9c720c24cdeffb624bfe0c2352353.tar.bz2
busybox-w32-8f2cb7ab26b9c720c24cdeffb624bfe0c2352353.zip
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>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/login.c3
-rw-r--r--libbb/time.c21
2 files changed, 22 insertions, 2 deletions
diff --git a/libbb/login.c b/libbb/login.c
index 8a82c6add..8f080b775 100644
--- a/libbb/login.c
+++ b/libbb/login.c
@@ -16,7 +16,6 @@
16#define LOGIN " login: " 16#define LOGIN " login: "
17 17
18static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y"; 18static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
19static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
20 19
21void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) 20void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
22{ 21{
@@ -73,7 +72,7 @@ void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
73 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); 72 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
74 break; 73 break;
75 case 't': 74 case 't':
76 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); 75 strftime_HHMMSS(buf, sizeof(buf), &t);
77 break; 76 break;
78 case 'l': 77 case 'l':
79 outbuf = tty; 78 outbuf = tty;
diff --git a/libbb/time.c b/libbb/time.c
index e2b938471..57e14b66c 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -187,6 +187,27 @@ time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *ptm)
187 return t; 187 return t;
188} 188}
189 189
190static char* strftime_fmt(char *buf, unsigned len, time_t *tp, const char *fmt)
191{
192 time_t t;
193 if (!tp) {
194 tp = &t;
195 time(tp);
196 }
197 /* Returns pointer to NUL */
198 return buf + strftime(buf, len, fmt, localtime(tp));
199}
200
201char* FAST_FUNC strftime_HHMMSS(char *buf, unsigned len, time_t *tp)
202{
203 return strftime_fmt(buf, len, tp, "%H:%M:%S");
204}
205
206char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
207{
208 return strftime_fmt(buf, len, tp, "%Y-%m-%d %H:%M:%S");
209}
210
190#if ENABLE_MONOTONIC_SYSCALL 211#if ENABLE_MONOTONIC_SYSCALL
191 212
192#include <sys/syscall.h> 213#include <sys/syscall.h>