Xinqi Bao's Git

Mark unused parameters, fix compiler warnings
[slstatus.git] / util.c
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 #include "util.h"
8
9 const char *
10 bprintf(const char *fmt, ...)
11 {
12 va_list ap;
13 size_t len;
14
15 va_start(ap, fmt);
16 len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
17 va_end(ap);
18
19 if (len >= sizeof(buf)) {
20 buf[sizeof(buf)-1] = '\0';
21 }
22
23 return buf;
24 }
25
26 int
27 pscanf(const char *path, const char *fmt, ...)
28 {
29 FILE *fp;
30 va_list ap;
31 int n;
32
33 if (!(fp = fopen(path, "r"))) {
34 fprintf(stderr, "fopen '%s': %s\n", path, strerror(errno));
35 return -1;
36 }
37 va_start(ap, fmt);
38 n = vfscanf(fp, fmt, ap);
39 va_end(ap);
40 fclose(fp);
41
42 return (n == EOF) ? -1 : n;
43 }