What's the difference between isdir() and S_ISDIR()?

This is a discussion on What's the difference between isdir() and S_ISDIR()? within the C++ Programming forums, part of the General Programming Boards category; I am reading linux's source code and I see 2 functions: isdir() and S_ISDIR() I can't find related definitions of ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    What's the difference between isdir() and S_ISDIR()?

    I am reading linux's source code and I see 2 functions:
    isdir() and S_ISDIR()

    I can't find related definitions of them. What's the difference between isdir() and S_ISDIR() ?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    More forums, better answers, eh? http://www.codeguru.com/forum/showth...hreadid=447132

    [edit] Alright, here's my shot at it . . . have to show we're better than codeguru, after all.

    As far as I can tell, isdir() isn't very standard. http://genome.jouy.inra.fr/doc/genom...leio/isdir.htm

    S_ISDIR(), on the other hand, is a very common macro in <sys/stat.h>, and is probably POSIX standard.

    And another thing -- S_ISDIR() is called on the result of stat(), and it just checks an integer, so it's very efficient. isdir() appears to take a filename as a string, however, so opening and checking that would be pretty inefficient.

    For more information about stat(): http://www.opengroup.org/onlinepubs/...ions/stat.html [/edit]
    Last edited by dwks; 02-27-2008 at 12:26 AM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21