[Intel-gfx] [PATCH igt v3] lib: Add simple sysfs accessors
Chris Wilson
chris at chris-wilson.co.uk
Fri May 27 18:07:27 UTC 2016
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
More information about the Intel-gfx
mailing list