diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-12 02:28:35 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-12 02:28:35 +0100 |
commit | 2e53afb10dbff3346079601579ee5eaaa5c1884e (patch) | |
tree | e6e9eb7aaac14622cc9512f1bf4cd36b12275602 | |
parent | begin on drm support (diff) | |
download | blueshift-2e53afb10dbff3346079601579ee5eaaa5c1884e.tar.gz blueshift-2e53afb10dbff3346079601579ee5eaaa5c1884e.tar.bz2 blueshift-2e53afb10dbff3346079601579ee5eaaa5c1884e.tar.xz |
count graphic cards
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/blueshift_drm_c.c | 46 |
1 files changed, 37 insertions, 9 deletions
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 <stdlib.h> #include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> #include <sys/types.h> -#include <dirent.h> +#include <limits.h> +#include <alloca.h> #include <xf86drm.h> #include <xf86drmMode.h> +#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; } |