isdirectory.c 675 B

12345678910111213141516171819202122232425262728293031
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
  6. * Permission has been granted to redistribute this code under GPL.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  9. */
  10. #include <sys/stat.h>
  11. #include "libbb.h"
  12. /*
  13. * Return TRUE if fileName is a directory.
  14. * Nonexistent files return FALSE.
  15. */
  16. int FAST_FUNC is_directory(const char *fileName, int followLinks)
  17. {
  18. int status;
  19. struct stat statBuf;
  20. if (followLinks)
  21. status = stat(fileName, &statBuf);
  22. else
  23. status = lstat(fileName, &statBuf);
  24. status = (status == 0 && S_ISDIR(statBuf.st_mode));
  25. return status;
  26. }