From: Lennart Poettering Date: Wed, 9 Aug 2017 17:01:18 +0000 (+0200) Subject: util-lib: add a new skip_dev_prefix() helper X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1af2863f2cc977ecc0bcbde641191627fc07a9f1;p=elogind.git util-lib: add a new skip_dev_prefix() helper This new helper removes a leading /dev if there is one. We have code doing this all over the place, let's unify this, and correct it while we are at it, by using path_startswith() rather than startswith() to drop the prefix. --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index f9d62978b..37da0b192 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -39,13 +39,13 @@ #include #include "alloc-util.h" +#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" #include "io-util.h" #include "log.h" #include "macro.h" -#include "path-util.h" #include "parse-util.h" #include "process-util.h" #include "socket-util.h" @@ -561,7 +561,6 @@ int terminal_vhangup(const char *name) { int vt_disallocate(const char *name) { _cleanup_close_ int fd = -1; - const char *e, *n; unsigned u; int r; @@ -569,8 +568,7 @@ int vt_disallocate(const char *name) { * (i.e. because it is the active one), at least clear it * entirely (including the scrollback buffer) */ - e = path_startswith(name, "/dev/"); - if (!e) + if (!startswith(name, "/dev/")) return -EINVAL; if (!tty_is_vc(name)) { @@ -589,11 +587,10 @@ int vt_disallocate(const char *name) { return 0; } - n = startswith(e, "tty"); - if (!n) + if (!startswith(name, "/dev/tty")) return -EINVAL; - r = safe_atou(n, &u); + r = safe_atou(name+8, &u); if (r < 0) return r;