[Toybox] Question for using toybuf in lspci

Felix Janda felix.janda at posteo.de
Thu Aug 1 14:41:30 PDT 2013


Kyungwan Han wrote:
> Hi, felix
> 
> I'm reading lspci code, and I have a question about below code.
> 
>  25   struct {
>  26     char class[16], vendor[16], device[16], module[256];
>  27   } *bufs = (void*)(toybuf + 2);
> 
> Could I know why you use '*bufs = (void*)(toybuf + 2);' instead of '*bufs =
> (void*)(toybuf);' ?
> 
> What does it mean '+2'?

The 2 is sizeof("0x") - 1.

The files /proc/$pid/class, /proc/$pid/vendor and /proc/$pid/device are
read to toybuf, toybuf + 16 and toybuf + 32 respectively. So bufs->class,
bufs->vendor, bufs->device will point to the numbers (as strings) without
the starting "0x" -- ready to be printed. I should have put a comment in
line 27.

Felix

 1375393290.0


More information about the Toybox mailing list