Re: dirent->d_type: DT_LNK oddness ?
Re: dirent->d_type: DT_LNK oddness ?
- Subject: Re: dirent->d_type: DT_LNK oddness ?
- From: Mike Mackovitch <email@hidden>
- Date: Tue, 25 Apr 2006 11:13:09 -0700
On Tue, Apr 25, 2006 at 01:11:09PM -0400, David Carpeneto wrote:
>
> Playing with BSD File routines & it seems that *every* file I retrieve
> info on via readdir that isn't a directory or a pipe/fifo has "DT_LNK"
> set.
>
> [...]
> DIR *dirp;
> struct dirent *dp;
>
> dirp = opendir(argv[1]);
> while ((dp = readdir(dirp)) != NULL) {
> printf("NAME IS : %s", dp->d_name);
> if (dp->d_type & DT_UNKNOWN) printf("\t\tUNKNOWN");
> if (dp->d_type & DT_DIR) printf("\t\tDIRECTORY");
> if (dp->d_type & DT_LNK) printf("\t\tLINK");
> if (dp->d_type & DT_FIFO) printf("\t\tPIPE");
> printf("\n");
The DT_* constants are not flags.
>From /usr/include/sys/dirent.h:
/*
* File types
*/
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
#define DT_DIR 4
#define DT_BLK 6
#define DT_REG 8
#define DT_LNK 10
#define DT_SOCK 12
#define DT_WHT 14
So, you probably want to try using "==" instead of "&" in
those tests.
HTH
--macko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden