LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2008, 01:11 AM   #1
smoking81
LQ Newbie
 
Registered: Sep 2008
Posts: 8

Rep: Reputation: 0
using lstat st_mode flags and masks


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 )
or would something like
Code:
if (statbuff.st_mode && S_IXUSR)
suffice?


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
 
Old 10-03-2008, 05:17 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
if( (statbuff.st_mode & S_IRWXU) && S_IXUSR )
You are mixing the logical and bitwise operators here. Checking that the user has read permissions is correct but then you use a logical and with S_IXUSR as this is none zero then it will always be true.

Code:
if (statbuff.st_mode && S_IXUSR)
Again here you have mixed your operators up.

Check for read and execute access
if( statbuff.st_mode & S_IRWXU && statbuff.st_mode & S_IXUSR )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rm: cannot lstat `/mnt/share1': Input/output error toadeny Linux - Networking 3 06-27-2008 02:40 AM
Where is lstat man page? sheintze Debian 6 03-20-2007 11:52 AM
wine: exists lstat socket : No such file or directory hisnumber666 Linux - Software 1 05-02-2006 02:35 AM
installed cedega get exists lstat socket error? degraffenried13 Linux - Games 2 05-28-2005 10:08 PM
error: failed to lstat /tmp/.302.2fa859: ferdog Linux - Newbie 7 07-18-2003 09:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration