aboutsummaryrefslogtreecommitdiffstats
path: root/src/strings.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2017-08-21 21:07:50 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-08-28 07:30:38 +0200
commit550a2e937906d7e3c821d7508901eea2dafd9344 (patch)
treec94df0db850d9d9e2455bf74d5b2d6a228db5948 /src/strings.c
parent0c63b4661f5006348f384519eb6a9eecfa3c3fb7 (diff)
downloadcalcurse-550a2e937906d7e3c821d7508901eea2dafd9344.tar.gz
calcurse-550a2e937906d7e3c821d7508901eea2dafd9344.zip
Extend strings API for formatted dates
Add two new functions string_catftime(), resp. string_strftime(), which can be used to append, resp. print, a formatted date to a dynamic string. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/strings.c')
-rw-r--r--src/strings.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/strings.c b/src/strings.c
index 816ddc1..6601a99 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -112,3 +112,23 @@ int string_printf(struct string *sb, const char *format, ...)
return n;
}
+
+int string_catftime(struct string *sb, const char *format, const struct tm *tm)
+{
+ int n = 0;
+
+ while (!n) {
+ string_grow(sb, sb->bufsize * 2);
+ n = strftime(sb->buf + sb->len, sb->bufsize - sb->len, format,
+ tm);
+ }
+ sb->len += n;
+
+ return n;
+}
+
+int string_strftime(struct string *sb, const char *format, const struct tm *tm)
+{
+ string_reset(sb);
+ return string_catftime(sb, format, tm);
+}