[comp.unix.questions] File types

dean@snkoil.mitre.org (Dean Cookson) (01/05/91)

Anyone know any easy way for a program to check if the argument it was
given as an input file is a directory??  I've been using stat, but
whatever more uses seems faster.

Thanks,
Dean
dean@snkoil.mitre.org

chet@odin.INS.CWRU.Edu (Chet Ramey) (01/10/91)

In article <127561@linus.mitre.org> dean@snkoil.mitre.org (Dean Cookson) writes:

>Anyone know any easy way for a program to check if the argument it was
>given as an input file is a directory??  I've been using stat, but
>whatever more uses seems faster.

Stat is what more uses.  You could try opening the file for writing and
checking to see if the open fails with errno == EISDIR, but I don't think
that's any better, and it has to be less portable.

Chet
-- 
Chet Ramey				``There's just no surf in
Network Services Group			  Cleveland, U.S.A. ...''
Case Western Reserve University
chet@ins.CWRU.Edu		My opinions are just those, and mine alone.

boyd@necisa.ho.necisa.oz.au (Boyd Roberts) (01/11/91)

In article <127561@linus.mitre.org> dean@snkoil.mitre.org (Dean Cookson) writes:
>Anyone know any easy way for a program to check if the argument it was
>given as an input file is a directory??  I've been using stat, but
>whatever more uses seems faster.
>

Use stat(2).


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''

jim@segue.segue.com (Jim Balter) (01/12/91)

In article <1991Jan10.130009.3973@usenet.ins.cwru.edu> chet@po.CWRU.Edu writes:
>In article <127561@linus.mitre.org> dean@snkoil.mitre.org (Dean Cookson) writes:
>Stat is what more uses.  You could try opening the file for writing and
>checking to see if the open fails with errno == EISDIR, but I don't think
>that's any better, and it has to be less portable.

Open the file for reading and then do an fstat.  That only does one nami,
instead of two for stat and open.