]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
strutils: add skip_space() function
authorOndrej Oprala <ooprala@redhat.com>
Mon, 23 Sep 2013 13:39:34 +0000 (15:39 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 8 Nov 2013 13:14:34 +0000 (14:14 +0100)
[kzak@redhat.com: - add also skip_blank(),
                  - remove duplicate implementation from libmount]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h
libmount/src/tab_parse.c

index c7fe42a6326756148fc6855df048d3318e53fb18..3883b4288f4aedac8d43c4e440323b67a02affba 100644 (file)
@@ -5,6 +5,7 @@
 #include <inttypes.h>
 #include <string.h>
 #include <sys/types.h>
+#include <ctype.h>
 
 /* default strtoxx_or_err() exit code */
 #ifndef STRTOXX_EXIT_CODE
@@ -143,4 +144,21 @@ static inline const char *endswith(const char *s, const char *postfix)
        return (char *)s + sl - pl;
 }
 
+/*
+ * Skip leading white space.
+ */
+static inline const char *skip_space(const char *p)
+{
+       while (isspace(*p))
+               ++p;
+       return p;
+}
+
+static inline const char *skip_blank(const char *p)
+{
+       while (isblank(*p))
+               ++p;
+       return p;
+}
+
 #endif
index 532f0ec04a40834689ac3508b4f7a97ef3793942..9246d420bd4315453ffdf38c4357401255e837c9 100644 (file)
 #include "pathnames.h"
 #include "strutils.h"
 
-static inline char *skip_spaces(char *s)
-{
-       assert(s);
-
-       while (*s == ' ' || *s == '\t')
-               s++;
-       return s;
-}
-
 static int next_number(char **s, int *num)
 {
        char *end = NULL;
@@ -38,7 +29,7 @@ static int next_number(char **s, int *num)
        assert(num);
        assert(s);
 
-       *s = skip_spaces(*s);
+       *s = (char *) skip_blank(*s);
        if (!**s)
                return -1;
        *num = strtol(*s, &end, 10);
@@ -111,7 +102,7 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s)
        fs->passno = fs->freq = 0;
 
        if (xrc == 4 && n)
-               s = skip_spaces(s + n);
+               s = (char *) skip_blank(s + n);
        if (xrc == 4 && *s) {
                if (next_number(&s, &fs->freq) != 0) {
                        if (*s) {
@@ -346,7 +337,7 @@ static int guess_table_format(char *line)
 
 static int is_comment_line(char *line)
 {
-       char *p = skip_spaces(line);
+       char *p = (char *) skip_blank(line);
 
        if (p && (*p == '#' || *p == '\n'))
                return 1;
@@ -474,7 +465,7 @@ next_line:
                *s = '\0';
                if (--s >= buf && *s == '\r')
                        *s = '\0';
-               s = skip_spaces(buf);
+               s = (char *) skip_blank(buf);
        } while (*s == '\0' || *s == '#');
 
        if (tb->fmt == MNT_FMT_GUESS) {