neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

devmajor-freebsd.c (2292B)


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