summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blueshift_drm_c.c46
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;
}