diff options
Diffstat (limited to '')
| -rw-r--r-- | slstatus/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/slstatus/util.c b/slstatus/util.c index bca9b2e..d33cf9d 100644 --- a/slstatus/util.c +++ b/slstatus/util.c @@ -139,3 +139,20 @@ pscanf(const char *path, const char *fmt, ...) return (n == EOF) ? -1 : n; } + +int +lscanf(FILE *fp, const char *key, const char *fmt, void *res) +{ + int n; + char line[256]; + + n = -1; + while (fgets(line, sizeof(line), fp)) + if (strncmp(line, key, strlen(key)) == 0) { + n = sscanf(line + strlen(key), fmt, res); + break; + } + + rewind(fp); + return (n == 1) ? 1 : -1; +} |
