summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-07-24 19:34:46 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-07-24 19:34:46 -0400
commit16a0d47fdce2bd6a2c7d63c97fca28b6ba4e3d9b (patch)
tree2a29909388573be5dda8ed24567283c7c8647ae9
parentc9280082b774bb8ec8aba7560887d21a661eee0e (diff)
downloadbfs-16a0d47fdce2bd6a2c7d63c97fca28b6ba4e3d9b.tar.xz
printf: Support all standard strftime() directives
-rw-r--r--printf.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/printf.c b/printf.c
index d57c570..0a969d8 100644
--- a/printf.c
+++ b/printf.c
@@ -149,15 +149,6 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf_directive *di
case '@':
ret = snprintf(buf, sizeof(buf), "%lld.%09ld0", (long long)ts->tv_sec, (long)ts->tv_nsec);
break;
- case 'k':
- ret = snprintf(buf, sizeof(buf), "%2d", tm.tm_hour);
- break;
- case 'l':
- ret = snprintf(buf, sizeof(buf), "%2d", (tm.tm_hour + 11)%12 + 1);
- break;
- case 'S':
- ret = snprintf(buf, sizeof(buf), "%.2d.%09ld0", tm.tm_sec, (long)ts->tv_nsec);
- break;
case '+':
ret = snprintf(buf, sizeof(buf), "%4d-%.2d-%.2d+%.2d:%.2d:%.2d.%09ld0",
1900 + tm.tm_year,
@@ -168,6 +159,25 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf_directive *di
tm.tm_sec,
(long)ts->tv_nsec);
break;
+ case 'k':
+ ret = snprintf(buf, sizeof(buf), "%2d", tm.tm_hour);
+ break;
+ case 'l':
+ ret = snprintf(buf, sizeof(buf), "%2d", (tm.tm_hour + 11)%12 + 1);
+ break;
+ case 's':
+ ret = snprintf(buf, sizeof(buf), "%lld", (long long)ts->tv_sec);
+ break;
+ case 'S':
+ ret = snprintf(buf, sizeof(buf), "%.2d.%09ld0", tm.tm_sec, (long)ts->tv_nsec);
+ break;
+ case 'T':
+ ret = snprintf(buf, sizeof(buf), "%.2d:%.2d:%.2d.%09ld0",
+ tm.tm_hour,
+ tm.tm_min,
+ tm.tm_sec,
+ (long)ts->tv_nsec);
+ break;
// POSIX strftime() features
default:
@@ -754,7 +764,7 @@ struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline)
cfprintf(cerr, "%{er}error: '%s': Incomplete time specifier '%s%c'.%{rs}\n",
format, directive->str, i[-1]);
goto directive_error;
- } else if (strchr("@HIklMprST+XZaAbBcdDhjmUwWxyY", c)) {
+ } else if (strchr("%+@aAbBcCdDeFgGhHIjklmMnprRsStTuUVwWxXyYzZ", c)) {
directive->c = c;
} else {
cfprintf(cerr, "%{er}error: '%s': Unrecognized time specifier '%%%c%c'.%{rs}\n",