Re: Testing if a file or directory exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Holger Kiehl wrote:

> >> What is the quickest way to test if a file or directory exist. I can
> >> think of three different system calls that can be used: access(),
> >> stat() and open(). Writting a little test program I found that this
> >> is also the order of which is the quickest, that is access() is the
> >> quickest and open() the slowest.
> >
> > if all you want to do is check for existence, then, execution time
> > notwithstanding, you should use the method which accomplishes that and
> > nothing more, so the obvious solution would be stat().
> 
> That is what I first thought as well. But I think the problem is that
> stat() needs to fill up the structure with all the data, is what takes
> most the time.

That isn't the case. All of the information returned by stat() is in
one place: the inode. stat() just copies various fields from the inode
into the "struct stat".

Most of the time taken would be in resolving the filename to an inode,
and in the system call overhead.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux