2001-03-16 22:47:14 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
2001-10-24 05:00:29 +00:00
|
|
|
* Permission has been granted to redistribute this code under the GPL.
|
2001-03-16 22:47:14 +00:00
|
|
|
*
|
2006-05-19 19:29:19 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-03-16 22:47:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE if a fileName is a directory.
|
2004-04-14 17:51:38 +00:00
|
|
|
* Nonexistent files return FALSE.
|
2001-03-16 22:47:14 +00:00
|
|
|
*/
|
|
|
|
int is_directory(const char *fileName, const int followLinks, struct stat *statBuf)
|
|
|
|
{
|
|
|
|
int status;
|
2003-05-26 14:07:50 +00:00
|
|
|
struct stat astatBuf;
|
2001-03-16 22:47:14 +00:00
|
|
|
|
|
|
|
if (statBuf == NULL) {
|
2003-05-26 14:07:50 +00:00
|
|
|
/* set from auto stack buffer */
|
|
|
|
statBuf = &astatBuf;
|
2001-03-16 22:47:14 +00:00
|
|
|
}
|
|
|
|
|
2001-12-20 23:13:26 +00:00
|
|
|
if (followLinks)
|
2001-03-16 22:47:14 +00:00
|
|
|
status = stat(fileName, statBuf);
|
|
|
|
else
|
|
|
|
status = lstat(fileName, statBuf);
|
|
|
|
|
|
|
|
if (status < 0 || !(S_ISDIR(statBuf->st_mode))) {
|
|
|
|
status = FALSE;
|
|
|
|
}
|
|
|
|
else status = TRUE;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|