From: lkml@woutersimons.org (Wouter Simons)
To: kernelnewbies@lists.kernelnewbies.org
Subject: get info in a loop from a sysfs entry
Date: Wed, 05 Jan 2011 09:35:39 +0100 [thread overview]
Message-ID: <4D242D5B.1080009@woutersimons.org> (raw)
In-Reply-To: <AANLkTi=GU0Ktm5EDvBX-XjzQbnfQiyf-oq4bYH-t45EB@mail.gmail.com>
On 01/04/2011 04:52 PM, Dave Hylands wrote:
> On Tue, Jan 4, 2011 at 2:48 AM, Wouter Simons <lkml@woutersimons.org> 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
prev parent reply other threads:[~2011-01-05 8:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-04 10:48 get info in a loop from a sysfs entry Wouter Simons
2011-01-04 12:46 ` Wouter Simons
2011-01-04 13:56 ` Greg KH
2011-01-04 14:35 ` Wouter Simons
2011-01-04 15:52 ` Dave Hylands
2011-01-05 8:35 ` Wouter Simons [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D242D5B.1080009@woutersimons.org \
--to=lkml@woutersimons.org \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.