is_dir.h 773 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef IGL_IS_DIR_H
  2. #define IGL_IS_DIR_H
  3. namespace igl
  4. {
  5. // Act like php's is_dir function
  6. // http://php.net/manual/en/function.is-dir.php
  7. // Tells whether the given filename is a directory.
  8. // Input:
  9. // filename Path to the file. If filename is a relative filename, it will
  10. // be checked relative to the current working directory.
  11. // Returns TRUE if the filename exists and is a directory, FALSE
  12. // otherwise.
  13. inline bool is_dir(const char * filename);
  14. }
  15. // Implementation
  16. #include <sys/stat.h>
  17. inline bool igl::is_dir(const char * filename)
  18. {
  19. struct stat status;
  20. if(stat(filename,&status)!=0)
  21. {
  22. // path does not exist
  23. return false;
  24. }
  25. // Tests whether existing path is a directory
  26. return S_ISDIR(status.st_mode);
  27. }
  28. #endif