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!!!
3 2772
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
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. - 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.
Sorry,
I missed the pint that he is writing a shell script.
Raghuram
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?
|
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...
|
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...
|
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,...
|
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....
|
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...
|
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...
|
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:...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
| |