From 2e53afb10dbff3346079601579ee5eaaa5c1884e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 12 Mar 2014 02:28:35 +0100 Subject: count graphic cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blueshift_drm_c.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/blueshift_drm_c.c b/src/blueshift_drm_c.c index 5007a24..629030c 100644 --- a/src/blueshift_drm_c.c +++ b/src/blueshift_drm_c.c @@ -16,29 +16,57 @@ */ #include #include +#include +#include +#include #include -#include +#include +#include #include #include +#ifndef PATH_MAX + #define PATH_MAX 4096 +#endif + /* Requires video group */ -int main(int argc, char** argv) +/** + * Get the number of cards present on the system + * + * @return The number of cards present on the system + */ +long card_count() { - DIR* dir; + char* pathname = alloca(PATH_MAX * sizeof(char)); + long len = strlen("/dev/dri/card"); + long count = 0; + struct stat attr; - (void) argc; - (void) argv; + memcpy(pathname, "/dev/dri/card", len); - if ((dir = opendir("/dev/dri")) == NULL) + for (;;) { - perror("opendir"); - return 1; + sprintf(pathname + len, "%li", count); + if (stat(pathname, &attr)) + break; + count++; } - free(dir); + return count; +} + + +int main(int argc, char** argv) +{ + (void) argc; + (void) argv; + + + printf("%li\n", card_count()); + return 0; } -- cgit v1.2.3-70-g09d2