is_dir.cpp 450 B

1234567891011121314151617181920212223
  1. #include "is_dir.h"
  2. #include <sys/stat.h>
  3. #ifndef S_ISDIR
  4. #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
  5. #endif
  6. #ifndef S_ISREG
  7. #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  8. #endif
  9. IGL_INLINE bool igl::is_dir(const char * filename)
  10. {
  11. struct stat status;
  12. if(stat(filename,&status)!=0)
  13. {
  14. // path does not exist
  15. return false;
  16. }
  17. // Tests whether existing path is a directory
  18. return S_ISDIR(status.st_mode);
  19. }