/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
#define buf bb_common_bufsiz1
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
+ strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
return buf;
#undef buf
}
void parse_datestr(const char *date_str, struct tm *ptm) FAST_FUNC;
time_t validate_tm_time(const char *date_str, struct tm *ptm) FAST_FUNC;
-
+char *strftime_HHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
+char *strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) FAST_FUNC;
int xsocket(int domain, int type, int protocol) FAST_FUNC;
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
#define LOGIN " login: "
static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y";
-static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
{
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
break;
case 't':
- strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
+ strftime_HHMMSS(buf, sizeof(buf), &t);
break;
case 'l':
outbuf = tty;
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>
VERB2 {
tval = tvc.tv_sec;
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&tval));
+ strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval);
bb_error_msg("current time is %s.%06u", buf, (unsigned)tvc.tv_usec);
}
tval = tvn.tv_sec;
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&tval));
+ strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval);
bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset);
/* Correct various fields which contain time-relative values: */
bb_perror_msg_and_die("settimeofday");
tval = tv.tv_sec;
- strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval));
+ strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval);
bb_error_msg("setting clock to %s (offset %fs)", buf, offset);
printf("\033[H""\033[J");
if (!(opt & 0x2)) { // no -t
const unsigned time_len = sizeof("1234-67-90 23:56:89");
- time_t t;
// STDERR_FILENO is procps3 compat:
// "watch ls 2>/dev/null" does not detect tty size
free(header);
header = xasprintf("Every %us: %-*s", period, (int)width, cmd);
}
- time(&t);
- if (time_len < width)
- strftime(header + width - time_len, time_len,
- "%Y-%m-%d %H:%M:%S", localtime(&t));
+ if (time_len < width) {
+ strftime_YYYYMMDDHHMMSS(
+ header + width - time_len,
+ time_len,
+ /*time_t*:*/ NULL
+ );
+ }
// compat: empty line between header and cmd output
printf("%s\n\n", header);