and said:
How can I controll the permissions on a file in a c program.Are there
any macros or I have to use bitwise operators on the st_mode member of
the stat structure?For example I want to know if a owner have read
permission on a file.How can I do it?Thank you.
The answer depends upon your operating system; the C standard doesn't
provide any generic mechanism for doing this; in particular, it doesn't
define a stat structure or an st_mode member thereof. You'll get the
best answers to a question about your particular operating system by
asking in a forum specific to that operating system, such as
comp.unix.programmer.
Do you want to "control the permissions" or "know if an owner ha
read
permission"? If you are in fact using a unix or unix-like system (such
as linux), then the function you want for learning about permissions is
stat(), and yes, you do have to extract the appropriate bit from st_mode
for which the bitwise operators are the most appropriate tool. If you
actually want to control the permissions, then the appropriate function
is chmod() - type "man 2 chmod" for more details.
Followups redirected to comp.unix.programmer.