]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Trim trailing whitespace.
authorRoy Marples <roy@marples.name>
Mon, 21 Apr 2008 09:53:18 +0000 (09:53 +0000)
committerRoy Marples <roy@marples.name>
Mon, 21 Apr 2008 09:53:18 +0000 (09:53 +0000)
dhcpcd.c

index 3c072631e91bfc8855f83c7dc09a7e31f1b37fe2..761eeaa5fb16a003e8d5b4e535ccee8b888b89ea 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -360,7 +360,7 @@ main(int argc, char **argv)
        int pidfd = -1;
        int sig = 0;
        int retval = EXIT_FAILURE;
-       char *line, *option, *buffer = NULL;
+       char *line, *option, *p, *buffer = NULL;
        size_t len = 0;
        FILE *f;
 
@@ -393,10 +393,17 @@ main(int argc, char **argv)
                        option = strsep(&line, " ");
                        if (!option || *option == '\0' || *option == '#')
                                continue;
-                       /* Trim whitespace */
-                       if (line)
-                               while (*line == ' ' || *line == '\t')
+                       /* Trim leading whitespace */
+                       if (line) {
+                               while (*line != '\0' && (*line == ' ' || *line == '\t'))
                                        line++;
+                       }
+                       /* Trim trailing whitespace */
+                       if (line && *line) {
+                               p = line + strlen(line) - 1;
+                               while (p != line && (*p == ' ' || *p == '\t'))
+                                       *p-- = '\0';
+                       }
                        r = parse_config_line(option, line, options);
                        if (r != 1)
                                break;