Re: A Q for C gurus

Colin Panisset (Colin.Panisset@nospam.nms.otc.com.au)
Fri, 20 Jan 1995 12:36:18 +1100 (EST)

Once upon a time, pmeric@nospam.vnet.IBM.COM was heard to say:

}
} What about the following adjustment.....
}
} Instea of using S_ISDIR(), which may or may not exist on particular
} compilers, such as Turbo C, let's do this....
}
} if ((buf.st_mode & S_IFDIR) == S_IFDIR) {
} /* is a dir*/
} ...
}
} This is possibly a little more portable - I couldn't find S_ISDIR()
} in Borland C or IBM CSet++.

Yeah, I guess so. stat(2v) says:

In addition, the following bits and masks are made available
for backward compatibility:
#define S_IFMT 0170000 /* type of file */
#define S_IFIFO 0010000 /* FIFO special */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
...

which was my initial choice. S_ISDIR() is semantically a little clearer,
though, which is why I used it. I don't have any PC compilers, either
:-).

-- Colin.