file_exists.h 563 B

1234567891011121314151617181920212223
  1. #ifndef IGL_FILE_EXISTS_H
  2. #define IGL_FILE_EXISTS_H
  3. namespace igl
  4. {
  5. // Check if a file or directory exists like PHP's file_exists function:
  6. // http://php.net/manual/en/function.file-exists.php
  7. // Input:
  8. // filename path to file
  9. // Returns true if file exists and is readable and false if file doesn't
  10. // exist or *is not readable*
  11. inline bool file_exists(const char * filename);
  12. }
  13. // Implementation
  14. #include <sys/stat.h>
  15. inline bool igl::file_exists(const char* filename)
  16. {
  17. struct stat status;
  18. return (stat(filename,&status)==0);
  19. }
  20. #endif