is_dir.cpp 796 B

123456789101112131415161718192021222324252627282930
  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_dir.h"
  9. #include <sys/stat.h>
  10. #ifndef S_ISDIR
  11. #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
  12. #endif
  13. #ifndef S_ISREG
  14. #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
  15. #endif
  16. IGL_INLINE bool igl::is_dir(const char * filename)
  17. {
  18. struct stat status;
  19. if(stat(filename,&status)!=0)
  20. {
  21. // path does not exist
  22. return false;
  23. }
  24. // Tests whether existing path is a directory
  25. return S_ISDIR(status.st_mode);
  26. }