is_file.cpp 746 B

1234567891011121314151617181920212223242526
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "is_file.h"
  9. #include <sys/stat.h>
  10. #ifdef _WIN32
  11. # ifndef S_ISREG
  12. # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  13. # endif
  14. #endif
  15. IGL_INLINE bool igl::is_file(const char * filename)
  16. {
  17. struct stat status;
  18. if(stat(filename,&status)!=0)
  19. {
  20. // path does not exist
  21. return false;
  22. }
  23. // Tests whether existing path is a regular file
  24. return S_ISREG(status.st_mode);
  25. }