linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Fwd: Re: Implementing a file counter (like "ls | wc")]
@ 2004-04-07 16:50 Luciano Moreira - igLnx
  2004-04-07 16:54 ` John T. Williams
  0 siblings, 1 reply; 7+ messages in thread
From: Luciano Moreira - igLnx @ 2004-04-07 16:50 UTC (permalink / raw)
  To: Holger Kiehl; +Cc: linux-c-programming

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
>
>
>  
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-08  8:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-07 16:50 [Fwd: Re: Implementing a file counter (like "ls | wc")] Luciano Moreira - igLnx
2004-04-07 16:54 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).