• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dirent->d_type: DT_LNK oddness ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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

  • Prev by Date: Re: Launchd and domain sockets, accept() problem (was Re: launchd APIs)
  • Next by Date: RE: dirent->d_type: DT_LNK oddness ?
  • Previous by thread: dirent->d_type: DT_LNK oddness ?
  • Next by thread: RE: dirent->d_type: DT_LNK oddness ?
  • Index(es):
    • Date
    • Thread