home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / c_spec / sources / isdir.c < prev    next >
C/C++ Source or Header  |  1986-02-20  |  669b  |  32 lines

  1. #include <types.h>
  2. #include <stat.h>
  3.  
  4. isdir( file )
  5. char    *file;
  6. {
  7.     /*    Return true if file exists and is a directory, false
  8.      *    otherwise. If stat returns non-existant then a disk
  9.      *    id if any is stripped off. If the resultant file name
  10.      *    is null,  .  ,  ..  or / then the root directory is
  11.      *    intended and 1 is returned.
  12.      */
  13.  
  14.     struct stat buf;
  15.  
  16.     if( !stat( file, &buf) )
  17.     {
  18.         if( buf.st_mode & S_IFDIR )
  19.             return 1;
  20.     }
  21.     else 
  22.     {
  23.         if( file[0] && file[1] == ':' )
  24.             file += 2;
  25.  
  26.         return(  ! file[0]  
  27.             || file[0] == '.'           && !file[1]
  28.             || file[0] == '/'           && !file[1]
  29.             || file[0] == '.' && file[1]=='.' && !file[2] );
  30.     }
  31. }
  32.