Subject: Re: sys/stat.h: S_IFLNK
To: Chris G. Demetriou <cgd@sibyte.com>
From: =?iso-8859-1?Q?Thorbj=F6rn?= jemander <thoan@ifm.liu.se>
List: tech-misc
Date: 01/10/2001 04:27:25
"Chris G. Demetriou" wrote:

> thoan@ifm.liu.se (Thorbjorn Jemander) writes:
> > So, here's some really basic stuff.
> > Why do regular files trigger this test:
> >
> > if (file_stat.st_mode & S_IFMT == S_IFLNK) {
> >       /* Symbolic link */
> > }
> >
> > ?
>
> I don't see how you'll _ever_ get into the /* Symbolic link */
> comment's block, there...

Ah, no sorry, there was a parenthesis missing there. Sorry for
that typo. What I do is a mask in a switch statement where
all other non-type bits are masked away with S_IFMT:

switch (file_stat.st_mode & S_IFMT) {
    case S_IFLNK:
        /* symbolic link */
        break;

    case  S_IFIFO:
        break;

    /* etc */
}

This should be equivalent with the #defines in sys/stat.h
for testing file types (where there parenthesis exists.)

The problem is not on a masking level, it's on
the file type flag  interpretation level. What does these flags
really mean (''character special '' for instance) and where
can I read about them?

Sorry for the confusion,
Thorbjörn