1/* swc: launch/devmajor-openbsd.c
2 *
3 * Copyright (c) 2020 Nia Alarie
4 * Copyright (c) 2026 uint
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "devmajor.h"
25#include <stdlib.h>
26#include <string.h>
27#include <sys/stat.h>
28
29static bool
30devname_is(dev_t rdev, const char *prefix)
31{
32 const char *name;
33 size_t len;
34
35 name = devname(rdev, S_IFCHR);
36 if (!name || name[0] == '?' || name[1] == '?') {
37 return false;
38 }
39
40 len = strlen(prefix);
41 return strncmp(name, prefix, len) == 0;
42}
43
44bool
45device_is_input(dev_t rdev)
46{
47 if (devname_is(rdev, "wskbd")) {
48 return true;
49 }
50 if (devname_is(rdev, "wsmouse")) {
51 return true;
52 }
53 if (devname_is(rdev, "wsmux")) {
54 return true;
55 }
56 return false;
57}
58
59bool
60device_is_tty(dev_t rdev)
61{
62 return devname_is(rdev, "ttyC");
63}
64
65bool
66device_is_drm(dev_t rdev)
67{
68 const char *n;
69
70 n = devname(rdev, S_IFCHR);
71 if (!n) {
72 return false;
73 }
74
75 return strncmp(n, "drm", 3) == 0 || strncmp(n, "dri/card", 8) == 0 ||
76 strncmp(n, "dri/renderD", 11) == 0;
77}