?
Solved

About file mode

Posted on 1999-07-06
5
Medium Priority
?
240 Views
Last Modified: 2010-04-15
I have questions about the st_mode in Unix
if I have a several statements like these:

1. STATS s;
2. int a;
3. a = s.st_mode&040777;
4. if (s.st_mode&0x1000)
5. {  ......  }
6. if (w&040000)
7. { ....... }

Q1. What does it mean to assign st_mode&.... to a/
Q2. On line 4 & 6, how do the conditional statements be   evaluated to be true or false?  
0
Comment
Question by:UTEK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
jshapiro earned 800 total points
ID: 1263344
The & is a bitwise AND.  I don't know much about st_mode but based on other similar examples the st_mode has a bunch of bits, each representing some flag like read-only, data, etc.  In line 3 you are setting a to contain the flags that are set for both s and the binary represenation of 40777.  In line 4 and 6 the bitwise and evaluates to 0 if there are no common flags set and TRUE if there is at least one
common flag set between the first variable and the binary
representation of the second variable.  I would need to
know more about st_mode to know exactly which flags.
0
 

Author Comment

by:UTEK
ID: 1263345
Thanks jshapiro.

I would give you those points if you can tell me about the st_mode representation. I understand the 777 but I am not quite sure about 040.
0
 

Expert Comment

by:jshapiro
ID: 1263346
It's rare to see bit comparisons with hard coded values,
mostly because the actual values may vary while the type names are usually the same.  These are the types for
st_mode.  
Constant Meaning
_S_IFMT File type mask
_S_IFDIR Directory
_S_IFCHR Character special (indicates a device if set)
_S_IFREG Regular
_S_IREAD Read permission, owner
_S_IWRITE Write permission, owner
_S_IEXEC Execute/search permission, owner
The values are in your sys/stat.h file.  4000 means the
file is really a directory but I can't seem to find
40000.
0
 

Author Comment

by:UTEK
ID: 1263347
Thanks jshapiro.

I would give you those points if you can tell me about the st_mode representation. I understand the 777 but I am not quite sure about 040.
0
 

Author Comment

by:UTEK
ID: 1263348
Thanks a lot.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question