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