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