Re: [PATCH igt v3] lib: Add simple sysfs accessors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 27, 2016 at 07:07:27PM +0100, Chris Wilson wrote:
> 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;

lgtm

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux