diff options
author | Vaclav Dolezal | 2017-08-29 14:31:06 +0200 |
---|---|---|
committer | Vaclav Dolezal | 2017-08-29 15:26:39 +0200 |
commit | 6c183c283bb7d5aadfa98c8fb218e4a9bb424e45 (patch) | |
tree | 0cf064fe1c64b2ee3c424ed6046ccdae20cb39fe | |
parent | fdisk: fix copy from readline and whitespace stripping (diff) | |
download | kernel-qcow2-util-linux-6c183c283bb7d5aadfa98c8fb218e4a9bb424e45.tar.gz kernel-qcow2-util-linux-6c183c283bb7d5aadfa98c8fb218e4a9bb424e45.tar.xz kernel-qcow2-util-linux-6c183c283bb7d5aadfa98c8fb218e4a9bb424e45.zip |
fdisk: use strutils to trim whitespace from input
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
-rw-r--r-- | disk-utils/fdisk.c | 7 | ||||
-rw-r--r-- | include/strutils.h | 2 |
2 files changed, 2 insertions, 7 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index be8f00edc..226f07065 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -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'; diff --git a/include/strutils.h b/include/strutils.h index be1ba6737..5d07fcc7c 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -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; |