I am trying to determine file types for directory entries (Windows Unix, etc.).
In sys / stat.h, the upper order of the high order st_mode is encoded:
#define S_IFDIR 0x4000 #define S_IFIFO 0x1000 #define S_IFCHR 0x2000 #define S_IFBLK 0x3000 #define S_IFREG 0x8000
From the comment, it seems that nybble could be 0 or 8 to represent a “regular file”.
So this asks the question: in what circumstances is it 0, not 8? If I defined these codes, I would have reserved 0 for failure unknown / undefined / invalid / not-a-file or something like that.
Indeed, the S_ISREG macro:
#define S_ISREG(m) ((m) & S_IFREG)
It seems to me that a regular file should always be expected to code 8 (and 0 would be aberration?).
Was it a valid assumption to interpret 0 as an unknown or invalid file and ignore the comment "or only 0x0000" and always expect 8 to be used for all regular files?
source share