DT_DIR undefined
11,632
You need to have the _BSD_SOURCE
feature test macro defined to get those defines, they are not standard, and GCC does not define that macro when compiling for C99.
gcc -std=c99 -D_BSD_SOURCE -Wall a.c
Author by
RiaD
Updated on June 04, 2022Comments
-
RiaD almost 2 years
I want to check if file returned by
readdir
is directory. I tried do it usingDT_DIR
constant (asman readdir
says) but it's undefined. What file should I include to get it?Now I use
#include <sys/types.h> #include <dirent.h> #include <stdlib.h> #include <errno.h>
gcc version is 4.6.1
Compilation string:
gcc a.c --std=c99 -Wall
-
RiaD about 12 yearsHm, thanks it works. But I guess it isn't always OK. to change this constant, because it may change something else. Is it way to do it other way? Are my own constants OK(i really don't think so) or they may be changed on other OS? (i.e 4 for me with directories)
-
RiaD about 12 yearsPS:
-D_BSD_SOURCE
is enough, we needn't value here -
Mat about 12 yearsUsing
-D_BSD_SOURCE
doesn't change any constants. It pulls in additional defines and functions that come from BSD and are not POSIX or standard C. If your code requires that, then it is not portable. If you want it to be portable, don't rely on thed_type
field ofstruct dirent
, usestat
instead. Hardcoding4
is a bad idea.