On Fri, May 27, 2016 at 08:46:14PM +0300, Ville Syrjälä wrote:
> > +   for (int n = 0; n < 16; n++) {
> > +           int len = sprintf(path, "/sys/class/drm/card%d", n);
> > +           if (device[0]) {
> > +                   char tmp[80];
> > +                   int ret;
> > +
> > +                   sprintf(path + len, "/dev");
> > +                   fd = open(path, O_RDONLY);
> > +                   if (fd == -1)
> > +                           continue;
> > +
> > +                   ret = read(fd, tmp, sizeof(tmp-1));
> > +                   if (ret < 0)
> > +                           ret = 0;
> > +                   tmp[ret] = '\0';
> > +                   while (ret > 0 && tmp[ret-1] == '\n')
> > +                           tmp[--ret] = '\0';
> > +                   close(fd);
> > +
> > +                   if (strcmp(tmp, device))
> > +                           continue;
> 
> fscanf?
                if (fd != -1) {
                        FILE *file;
                        int ret, maj, min;

                        sprintf(path + len, "/dev");
                        file = fopen(path, "r");
                        if (!file)
                                continue;

                        ret = fscanf(file, "%d:%d", &maj, &min);
                        fclose(file);

                        if (ret != 2 ||
                            major(st.st_rdev) != maj ||
                            minor(st.st_rdev) != min)
                                continue;

-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to