www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/05/01/16:19:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
From: Martin Str|mberg <ams AT ludd DOT ltu DOT se>
Message-Id: <201305011954.r41JsMnW006530@dexter.ludd.ltu.se>
Subject: Re: The encoding of S_IFREG
To: djgpp-workers AT delorie DOT com
Date: Wed, 1 May 2013 21:54:22 +0200 (MEST)
In-Reply-To: <5180E8C7.4010609@gmx.de> from "Juan Manuel Guerrero" at May 01, 2013 12:04:55 PM
X-Mailer: ELM [version 2.5 PL6]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

According to Juan Manuel Guerrero:
> Currently the following encodings are used:
> 
> #define S_IFMT        0xf000
> 
> #define S_IFREG        0x0000
> #define S_IFBLK        0x1000
> #define S_IFCHR        0x2000
> #define S_IFDIR        0x3000
> #define S_IFIFO        0x4000
> #define S_IFLNK         0x8000
> 
> #define S_IFLABEL    0x5000
> 
> We could replace 0x0000 by 0x6000.  I am aware that this may introduce 

IIUC, you'd use the above constants like this:

struct stat buf;
if( ! stat(path, &buf) ) {
  int type = S_IFMT & buf.st_mode;

  switch( type ) {
    case S_IFBLK: // Block device.

      break;
    case S_IFDIR: // Dir.

      break;
    case S_IFREG: // Regular file.

      break;
}

I'd think the thinking was, set a bit to indicate some special thing
about this "file". So if no bit is set then it must be a regular file.

Two comments:

1. Why would 0 not be a valid indication? Does a/the spec say so? I
think this is a bug in the code your trying to port.

2. Is st_mode 16 bits in DJGPP? Otherwise why not use 0x10000?


Thank you!


-- 
MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019