2001-03-17 06:47:14 +08:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 16:29:22 +08:00
|
|
|
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
2010-08-17 02:14:46 +08:00
|
|
|
* Permission has been granted to redistribute this code under GPL.
|
2001-03-17 06:47:14 +08:00
|
|
|
*
|
2010-08-17 02:14:46 +08:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2001-03-17 06:47:14 +08:00
|
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
/*
|
2008-02-26 04:30:24 +08:00
|
|
|
* Return TRUE if fileName is a directory.
|
2004-04-15 01:51:38 +08:00
|
|
|
* Nonexistent files return FALSE.
|
2001-03-17 06:47:14 +08:00
|
|
|
*/
|
2011-12-18 10:27:46 +08:00
|
|
|
int FAST_FUNC is_directory(const char *fileName, int followLinks)
|
2001-03-17 06:47:14 +08:00
|
|
|
{
|
|
|
|
int status;
|
2011-12-18 10:27:46 +08:00
|
|
|
struct stat statBuf;
|
2001-03-17 06:47:14 +08:00
|
|
|
|
2001-12-21 07:13:26 +08:00
|
|
|
if (followLinks)
|
2011-12-18 10:27:46 +08:00
|
|
|
status = stat(fileName, &statBuf);
|
2001-03-17 06:47:14 +08:00
|
|
|
else
|
2011-12-18 10:27:46 +08:00
|
|
|
status = lstat(fileName, &statBuf);
|
2001-03-17 06:47:14 +08:00
|
|
|
|
2011-12-18 10:27:46 +08:00
|
|
|
status = (status == 0 && S_ISDIR(statBuf.st_mode));
|
2001-03-17 06:47:14 +08:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|