diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-07 21:59:34 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-07 21:59:34 +0100 |
commit | 2aa3a2cbe7667ade5903c18d6719cf54cfaceb9e (patch) | |
tree | a2eee84eb8248ff9705be547225c6d895bd6100f /src/scrotty.c | |
parent | deps: alloca (diff) | |
download | scrotty-2aa3a2cbe7667ade5903c18d6719cf54cfaceb9e.tar.gz scrotty-2aa3a2cbe7667ade5903c18d6719cf54cfaceb9e.tar.bz2 scrotty-2aa3a2cbe7667ade5903c18d6719cf54cfaceb9e.tar.xz |
small fixes
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/scrotty.c')
-rw-r--r-- | src/scrotty.c | 14 |
1 files changed, 10 insertions, 4 deletions
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 <stdio.h> #include <unistd.h> #include <errno.h> @@ -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 } |