]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use strutils to trim whitespace from input
authorVaclav Dolezal <vdolezal@redhat.com>
Tue, 29 Aug 2017 12:31:06 +0000 (14:31 +0200)
committerVaclav Dolezal <vdolezal@redhat.com>
Tue, 29 Aug 2017 13:26:39 +0000 (15:26 +0200)
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
disk-utils/fdisk.c
include/strutils.h

index be8f00edc904eca8ef77b9d4f36989592cfe2dc7..226f0706516719f969d5e5e9aaa9442d9c6c588c 100644 (file)
@@ -97,7 +97,6 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz)
        struct pollfd fds[] = {
                { .fd = fileno(stdin), .events = POLLIN }
        };
-       char *p;
        size_t sz;
        int ret = 0;
 
@@ -165,11 +164,7 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz)
        /*
         * cleanup the reply
         */
-       for (p = buf; *p && !isgraph(*p); p++); /* get first non-blank */
-
-       if (p > buf)
-               memmove(buf, p, strlen(p) + 1); /* remove blank space */
-       sz = strlen(buf);
+       sz = ltrim_whitespace((unsigned char *) buf);
        if (sz && *(buf + sz - 1) == '\n')
                *(buf + sz - 1) = '\0';
 
index be1ba67371d87a1e039e032851dbc8735f275b1d..5d07fcc7c010ccbbb0400bedb04ea7f021b5a751 100644 (file)
@@ -213,7 +213,7 @@ static inline size_t ltrim_whitespace(unsigned char *str)
 
        len = strlen((char *) p);
 
-       if (len && p > str)
+       if (p > str)
                memmove(str, p, len + 1);
 
        return len;