1 /* $NetBSD: isdir.c,v 1.1.1.1 2016/01/10 21:36:18 christos Exp $ */
2
3 /* isdir.c -- determine whether a directory exists
4 Copyright (C) 1990, 1998 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26
27 #if STAT_MACROS_BROKEN
28 # undef S_ISDIR
29 #endif
30
31 #if !defined S_ISDIR && defined S_IFDIR
32 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
33 #endif
34
35 /* If PATH is an existing directory or symbolic link to a directory,
36 return nonzero, else 0. */
37
38 int
isdir(const char * path)39 isdir (const char *path)
40 {
41 struct stat stats;
42
43 return stat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
44 }
45