From 038e48492eb342a2128208e1ce171091174b1ae8 Mon Sep 17 00:00:00 2001 From: jsg Date: Fri, 25 Nov 2016 23:41:29 +0000 Subject: [PATCH] Implement drmGetMinorNameForFD for systems without sysfs by adapting drm_get_device_name_for_fd() from the Mesa loader. ok kettenis@ --- lib/libdrm/xf86drm.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/libdrm/xf86drm.c b/lib/libdrm/xf86drm.c index 3c2c5d4b9..9fec64b26 100644 --- a/lib/libdrm/xf86drm.c +++ b/lib/libdrm/xf86drm.c @@ -2851,7 +2851,25 @@ static char *drmGetMinorNameForFD(int fd, int type) out_close_dir: closedir(sysdir); #else -#warning "Missing implementation of drmGetMinorNameForFD" + struct stat sbuf; + unsigned int maj, min; + char buf[PATH_MAX + 1]; + int n; + + if (fstat(fd, &sbuf)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + return NULL; + + n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, min); + if (n == -1 || n >= sizeof(buf)) + return NULL; + + return strdup(buf); #endif return NULL; }