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

  1. #1
    Registered User
    Join Date
    Apr 2007

    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
    More forums, better answers, eh?

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

    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(): [/edit]
    Last edited by dwks; 02-27-2008 at 01:26 AM.

    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:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed