chiark / gitweb /
util-lib: add a new skip_dev_prefix() helper
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Aug 2017 17:01:18 +0000 (19:01 +0200)
committerSven Eden <yamakuzure@gmx.net>
Mon, 25 Sep 2017 12:30:39 +0000 (14:30 +0200)
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.

src/basic/terminal-util.c

index f9d62978b80e22a5ef71c3f66f0685ddf5aea779..37da0b192ccea600ca88addf70d0f3c65b6ef9d7 100644 (file)
 #include <unistd.h>
 
 #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;