Thread: using lstat st_mode flags

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    100

    using lstat st_mode flags

    hello everybody!
    i am a bit confused about the way the flags and masks defined for st_mode have to be used..
    Suppose that I lstat-ed a file and want to retrieve first is permission in numeric format (eg 755) and then simply check if the owner has execute permission..
    In the second simplier case, I shall write something like:

    Code:
    if( (statbuff.st_mode & S_IRWXU) && S_IXUSR )
    isn't it?

    in the second case,isn't there a faster way to get the numbers 7 5 5 than making all the comparisons possible?


    thanks! Bye
    /* NO COMMENT */

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    and want to retrieve first is permission in numeric format (eg 755)
    What?

    (statbuff.st_mode & S_IRWXU) && S_IXUSR
    Assuming that S_IRWXU is a bitmask, this checks if any of those bits are set in st_mode and also if the constant S_IXUSR has a value other than 0 (I assume it has).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-15-2008, 02:27 AM
  2. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 3
    Last Post: 04-14-2008, 02:29 AM
  3. Using 'flags'
    By cyreon in forum C++ Programming
    Replies: 11
    Last Post: 01-28-2008, 04:21 PM
  4. Bit Flags
    By Padawan in forum C Programming
    Replies: 15
    Last Post: 03-30-2004, 10:38 PM
  5. Flags, the ambiguity of
    By Jeremy G in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2003, 11:41 PM