Parse recovery.conf file

This will be useful for various kinds of diagnostics.
This commit is contained in:
Ian Barwick
2017-08-10 23:58:16 +09:00
parent 1292e8991a
commit f972aec198
5 changed files with 208 additions and 44 deletions

View File

@@ -255,3 +255,31 @@ string_remove_trailing_newlines(char *string)
return string;
}
char *
trim(char *s)
{
/* Initialize start, end pointers */
char *s1 = s,
*s2 = &s[strlen(s) - 1];
/* If string is empty, no action needed */
if (s2 < s1)
return s;
/* Trim and delimit right side */
while ((isspace(*s2)) && (s2 >= s1))
--s2;
*(s2 + 1) = '\0';
/* Trim left side */
while ((isspace(*s1)) && (s1 < s2))
++s1;
/* Copy finished string */
memmove(s, s1, s2 - s1);
s[s2 - s1 + 1] = '\0';
return s;
}