473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Finding access permissions in UNIX C

schmals
Hello,

I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. I know the stat struct contains mode_t st_mode which has the file type and access permissions encoded within it. It is easy to recover the file type from the variable because there are macro functions which will return true if the file is of that type. I need to decode the 9 access permissions from this variable though and I can't figure out how. I know there are functions such as umask() and chmod() which will set the access permissions for a current process or given file, but that doesn't really help me in my case. Basically, I just need to be educated on whether there is a function that will tell me the access permissions given the st_mode variable, or any tips to decode the access permissions from the variable itself.

Thank you very much!!!
May 12 '08 #1
3 2772
gpraghuram
1,275 Expert 1GB
Hello,

I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. I know the stat struct contains mode_t st_mode which has the file type and access permissions encoded within it. It is easy to recover the file type from the variable because there are macro functions which will return true if the file is of that type. I need to decode the 9 access permissions from this variable though and I can't figure out how. I know there are functions such as umask() and chmod() which will set the access permissions for a current process or given file, but that doesn't really help me in my case. Basically, I just need to be educated on whether there is a function that will tell me the access permissions given the st_mode variable, or any tips to decode the access permissions from the variable itself.

Thank you very much!!!
Check this link
This provide some info about the mode

raghuram
May 12 '08 #2
RRick
463 Expert 256MB
Mode_t is part of the C unix API and is not directly accessed via a script. If you want to use mode_t, you need to make a C program with it and then compile and run the program.

Shell scripts have a more direct method for retrieving this information. Try using the following shell stat command.
Expand|Select|Wrap|Line Numbers
  1. stat -c "%A" .../fileName
This returns a string (i.e. "-rwxr-xr--") that you can parse for permissions info. There are a host of other options you can use with stat, too. On a unix box, type in man stat for more info.
May 14 '08 #3
gpraghuram
1,275 Expert 1GB
Sorry,
I missed the pint that he is writing a shell script.

Raghuram
May 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jay Moore | last post by:
Greetings, all! I have a project for work, and I'm not sure how to efficiently do what I need to do. I'm hoping someone out there can help. Project is this: I'm creating a web-based...
6
by: Hayden Kirk | last post by:
PHP has encountered an Access Violation at 00B973CD OS: Windows XP Pro SP1 No MySQL... 3200xp with 1gb DDR... RC2 had the same problem... any idea?
5
by: Kenny Ashton | last post by:
Can anyone tell me how to overcome my 'permissions problems' every time I upload a new database to my ISP's server. I have a folder, specially created for me by the ISP, where I can upload new...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
4
by: Jake Peters | last post by:
I'd like to know how to get a users various table privilages from a sql server (insert/delete/update), so that i can set controls to behave accordingly (read only, hidden, disable "insert" button,...
5
by: Paul | last post by:
I am trying to create a log of certain events on the website by writing them to a text file. The logging code is in an "included" file that is inserted into the pages that need to be monitored....
5
by: =?Utf-8?B?Qkw=?= | last post by:
Hello friends In c# 2005 I have written a function to access "font file name" by "Font name" and it is working fine in all the windows version other than vista, in vista it is throughing an...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
9
by: Sam Lambson | last post by:
Hi, This is similar to another post, because I still haven't gotten to the bottom of it. I have a back end database on a shared drive. Each (of 4) user has a front end file on their own C:...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.