From fbfef469018f47e9f6710a727c5db002539e52f0 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 28 Oct 2014 09:44:20 +0100 Subject: m doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/scrotty.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/scrotty.c b/src/scrotty.c index 286a30d..c7e98ee 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -320,7 +320,8 @@ static int evaluate(char* restrict buf, size_t n, const char* restrict pattern, char* fmt; time_t t; struct tm tm; - + + /* Expand '$' and '\'. */ while ((c = *pattern++)) { if (dollar) @@ -358,12 +359,15 @@ static int evaluate(char* restrict buf, size_t n, const char* restrict pattern, } buf[i] = '\0'; + /* Check whether there are any '%' to expand. */ if (strchr(buf, '%') == NULL) return 0; + /* Copy the buffer so we can reuse the buffer and use its old content for the format. */ fmt = alloca((strlen(buf) + 1) * sizeof(char)); memcpy(fmt, buf, (strlen(buf) + 1) * sizeof(char)); + /* Expand '%'. */ t = time(NULL); localtime_r(&t, &tm); if (strftime(buf, n, fmt, &tm) == 0) -- cgit v1.2.3-70-g09d2