Re: [ProgSoc] C programming: mode_t mask question

Dennis Clark (dbugger@nospam.dbugger.rpi.net.au)
Thu, 5 Jun 1997 13:51:02 +1000


On Jun 5 1997, Peter Lees wrote:
| g'day
|
| i have a C- prorgamming question related to filemodes.
| (actually it's about using bit-masks, i think)
|
[...]
|
| the system (<sys/stat.h>) defines a set of constants, including
|
| #define S_ISUID 0x800 /* set user id on execution */
| #define S_IXGRP 00010 /* execute permission: group */
|
[...]
|
| how can i now determine that program_name is SETUID, and then
| that it is NOT group executable?

Test them seperately:

(program_filemode & S_ISUID) && !(program_filemode & S_IXGRP)

And yes, I've tested it myself first :-)

The simple rule is to use & (bit-wise AND) to test bits, | (bit-wise OR)
to set bits, and ~ (bit-wise complement) to invert bit masks (ie. to
apply the test/set to all the bits except the ones you specified).

Cheers,

-- 
     Dennis Clark     dbugger@nospam.progsoc.uts.edu.au     PGP/MIME spoken here
-------------------------------------------------------------------------------
    All language designers are arrogant.  Goes with the territory... :-)
	    --Larry Wall in <1991Jul13.010945.19157@nospam.netlabs.com
--
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.

This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>