3
0

isdirectory.c 652 B

1234567891011121314151617181920212223242526272829
  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 "libbb.h"
  11. /*
  12. * Return TRUE if fileName is a directory.
  13. * Nonexistent files return FALSE.
  14. */
  15. int FAST_FUNC is_directory(const char *fileName, int followLinks)
  16. {
  17. int status;
  18. struct stat statBuf;
  19. if (followLinks)
  20. status = stat(fileName, &statBuf);
  21. else
  22. status = lstat(fileName, &statBuf);
  23. status = (status == 0 && S_ISDIR(statBuf.st_mode));
  24. return status;
  25. }