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