--- slstatus.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/slstatus.c b/slstatus.c index ef79b03..79faeb3 100644 --- a/slstatus.c +++ b/slstatus.c _AT_@ -100,18 +100,21 @@ bprintf(const char *fmt, ...) int pscanf(const char *path, const char *fmt, ...) { - FILE *fp; + static FILE *fp; va_list ap; int n; - if (!(fp = fopen(path, "r"))) { - warn("fopen %s: %s\n", path, strerror(errno)); - return -1; + if (path) { + if (fp) + fclose(fp); + if (!(fp = fopen(path, "r"))) { + warn("fopen %s: %s\n", path, strerror(errno)); + return -1; + } } va_start(ap, fmt); n = vfscanf(fp, fmt, ap); va_end(ap); - fclose(fp); return (n == EOF) ? -1 : n; } -- 1.8.5.rc3Received on Fri Sep 15 2017 - 19:50:47 CEST
This archive was generated by hypermail 2.3.0 : Fri Sep 15 2017 - 20:00:35 CEST