From: lkml@woutersimons.org (Wouter Simons) Date: Wed, 05 Jan 2011 09:35:39 +0100 Subject: get info in a loop from a sysfs entry In-Reply-To: References: <4D22FAFB.20207@woutersimons.org> Message-ID: <4D242D5B.1080009@woutersimons.org> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On 01/04/2011 04:52 PM, Dave Hylands wrote: > On Tue, Jan 4, 2011 at 2:48 AM, Wouter Simons wrote: >> >> for (i = 0; i < count; i++) { >> if (fscanf(fd_next, "0x%X", &sample) != 1) { /* No data */ >> continue; >> } > > I would change this to use unbuffered I/O routines (i.e. > open/read/lseek/close) and use sscanf rather than fscanf. > fopen/fread/fseek/fclose use buffering by default. > > That would eliminate any buffering that the user side runtime library > is doing. I suspect that because the data is buffered by the FILE * > routines, even doing the seek is just re-returning the data that was > read the first time around. Thanks Dave, a quick test application shows that your solution works perfectly. This saves me a lot of overhead! Best regards, Wouter