From: Luciano Moreira - igLnx <lucianolnx@ig.com.br>
To: Holger Kiehl <Holger.Kiehl@dwd.de>
Cc: linux-c-programming@vger.kernel.org
Subject: [Fwd: Re: Implementing a file counter (like "ls | wc")]
Date: Wed, 07 Apr 2004 13:50:02 -0300 [thread overview]
Message-ID: <4074313A.5090808@ig.com.br> (raw)
Does exist another way to detect a directory without stat() ?
Luciano
Holger Kiehl wrote:
>On Wed, 7 Apr 2004, Luciano Moreira - igLnx wrote:
>
>
>
>>-------------- THE CODE HAVE THIS STRUCTURE:
>>while ((pFile=readdir(pDir))!=NULL) {
>> sprintf(szBuf, "%s/%s", pPath, pFile->d_name);
>> stat(szBuf, &statFile);
>> if (S_ISDIR(statFile.st_mode)) /// LOOK THAT: We don't use recursive
>>searching, we count only files at current directory excluding others
>>directories.
>> continue;
>>
>> /* Filtering */
>> if (nNeedFilter) {
>> //// I DONT HAVE THE CODE OF FILTERING NOW
>> //// BUT I CAN SEND IT LATER IF NECESSARY
>> }
>>
>> }
>>-------------- CODE FINISH HERE
>>
>>
>>
>Don't use sprintf(), its very expansive. Before the while loop put a pointer
>after path and / and then strcpy(ptr, pFile->d_name)
>
>stat() is _very_ epansive! It means physical IO and fills up a structure
>with things you just don't need. If you really do need to filter out
>directories from your result do the stat after it has passed the filter.
>
>
>
>>Does have another mechanism to filter without using of strcmp() / memcmp() ?
>>How if we dont know the size of extension (.c, .cpp, .teste, .longextension,
>>and so on). ?
>>
>>
>>
>Compare them yourself with a pointer byte for byte. But the speed gain
>will not be so high as when you leave away the stat() call.
>
>Holger
>
>
>
>
next reply other threads:[~2004-04-07 16:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-07 16:50 Luciano Moreira - igLnx [this message]
2004-04-07 16:54 ` [Fwd: Re: Implementing a file counter (like "ls | wc")] John T. Williams
2004-04-07 22:29 ` Holger Kiehl
2004-04-08 0:06 ` A. Murat Eren
2004-04-08 1:01 ` John T. Williams
2004-04-08 4:39 ` Glynn Clements
2004-04-08 8:05 ` A. Murat Eren
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=4074313A.5090808@ig.com.br \
--to=lucianolnx@ig.com.br \
--cc=Holger.Kiehl@dwd.de \
--cc=linux-c-programming@vger.kernel.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.