From 2aa3a2cbe7667ade5903c18d6719cf54cfaceb9e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 7 Dec 2015 21:59:34 +0100 Subject: small fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/scrotty.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/scrotty.c b/src/scrotty.c index 1005cff..7b621f4 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -23,6 +23,7 @@ #endif +#define _POSIX_SOURCE #include #include #include @@ -416,9 +417,9 @@ static int evaluate (char *restrict buf, size_t n, const char *restrict pattern, ssize_t j = 0; int percent = 0, backslash = 0, dollar = 0, r; char c; - char* fmt; + char *fmt; time_t t; - struct tm tm; + struct tm *tm; /* Expand '$' and '\'. */ while ((c = *pattern++)) @@ -468,12 +469,14 @@ static int evaluate (char *restrict buf, size_t n, const char *restrict pattern, /* Expand '%'. */ t = time (NULL); - localtime_r (&t, &tm); + tm = localtime (&t); + if (tm == NULL) + goto fail; #ifdef __GNUC__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif - if (strftime (buf, n, fmt, &tm) == 0) + if (strftime (buf, n, fmt, tm) == 0) goto enametoolong; /* No errors are defined for `strftime`. */ #ifdef __GNUC__ # pragma GCC diagnostic pop @@ -484,6 +487,9 @@ static int evaluate (char *restrict buf, size_t n, const char *restrict pattern, enametoolong: return errno = ENAMETOOLONG, -1; + fail: + return -1; + #undef P } -- cgit v1.2.3-70-g09d2