Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dirent->d_type: DT_LNK oddness ?



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:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden

References: 
 >dirent->d_type: DT_LNK oddness ? (From: "David Carpeneto" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.