aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2007-12-01 20:02:01 +0000
committerRafael J. Wysocki <rjw@sisk.pl>2007-12-01 20:02:01 +0000
commit1619fb151a6e01f95761b2612b6d6091ede8f468 (patch)
tree03fc83fcfd07ffefd8144438b8796ef056bb7859
parent5b0076d7e375ee580b01e6af0bcb03f2635f9301 (diff)
downloadsuspend-utils-1619fb151a6e01f95761b2612b6d6091ede8f468.tar.gz
Patch from Alon Bar-Lev <alon.barlev@gmail.com> to fix the problem of trailing
spaces in the s2disk/s2both configuration file and to use standard library functions for finding space characters.
-rw-r--r--config_parser.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/config_parser.c b/config_parser.c
index 30744e7..d017ccd 100644
--- a/config_parser.c
+++ b/config_parser.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <ctype.h>
#include <getopt.h>
#include "config_parser.h"
@@ -23,12 +24,12 @@
int parse_line(char *str, struct config_par *parv)
{
- char *dst, *fmt;
+ char *fmt, *end;
int error = 0;
int i, k;
/* Skip white space */
- while (*str == ' ' || *str == '\t' || *str == '\r' || *str == '\n')
+ while (isspace(*str))
str++;
/* Skip the lines containing white space only */
if (!*str)
@@ -44,27 +45,25 @@ int parse_line(char *str, struct config_par *parv)
if (!parv[i].ptr)
break;
str += k;
- while (*str == ' ' || *str == '\t')
+ while (isblank(*str))
str++;
if (*str != ':' && *str != '=') {
error = -EINVAL;
break;
}
str++;
- while (*str == ' ' || *str == '\t')
+ while (isblank(*str))
str++;
+ end = str + strlen(str);
+ while (end > str && isspace(*--end))
+ *end = '\0';
if (*str) {
fmt = parv[i].fmt;
- if (!strncmp(fmt, "%s", 2)) {
- dst = parv[i].ptr;
- k = parv[i].len;
- strncpy(dst, str, k - 1);
- k = strlen(dst) - 1;
- if (dst[k] == '\n')
- dst[k] = '\0';
- } else {
- k = sscanf(str, fmt, parv[i].ptr);
- if (k <= 0)
+ if (!strncmp(fmt, "%s", 2))
+ strncpy(parv[i].ptr, str,
+ parv[i].len - 1);
+ else {
+ if (sscanf(str, fmt, parv[i].ptr) <= 0)
error = -EINVAL;
}
break;