diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-21 15:37:09 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-07-21 15:37:09 +0000 |
commit | cf460de5fcf0ad6a1b169bbe1921944045751732 (patch) | |
tree | 0349e927c8547f1a622f92011f4c10f8edd7b478 /sys/lib/libsa/readdir.c | |
parent | de6d3e48f884473dc19b0eb5569d6a2210f8a2c6 (diff) |
do opendir for dirs only
Diffstat (limited to 'sys/lib/libsa/readdir.c')
-rw-r--r-- | sys/lib/libsa/readdir.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/sys/lib/libsa/readdir.c b/sys/lib/libsa/readdir.c index b01ecdda9b0..67c0340ff11 100644 --- a/sys/lib/libsa/readdir.c +++ b/sys/lib/libsa/readdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readdir.c,v 1.2 1997/04/02 05:20:02 mickey Exp $ */ +/* $OpenBSD: readdir.c,v 1.3 1997/07/21 15:37:08 mickey Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -35,6 +35,7 @@ #ifndef NO_READDIR #include <sys/types.h> +#include <sys/stat.h> #define _KERNEL #include <sys/fcntl.h> #undef _KERNEL @@ -46,16 +47,22 @@ opendir(name) char *name; { int fd; + struct stat sb; + if (stat(name, &sb) < 0) + return -1; + + if (!S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; + return -1; + } + + /* XXX rewind needed for some dirs */ #ifdef __INTERNAL_LIBSA_CREAD if ((fd = oopen(name, O_RDONLY)) >= 0) -#else - if ((fd = open(name, O_RDONLY)) >= 0) -#endif - /* XXX it's needed for some dirs */ -#ifdef __INTERNAL_LIBSA_CREAD olseek(fd, 0, 0); #else + if ((fd = open(name, O_RDONLY)) >= 0) lseek(fd, 0, 0); #endif |