Obtain the base file permissions to compare with the entry in C
source link: https://www.codesd.com/item/obtain-the-base-file-permissions-to-compare-with-the-entry-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Obtain the base file permissions to compare with the entry in C
I need to compare a basic file permission from a file with a file permission from input. The input should be saved in argv[1]
, and the permission information from file is stored in the classical struct stat stat_buf
, specifically in the stat_buf.st_mode
field.
An example of execution would be ./program 775
. Then the program must say that is the same permission of some file's stat_buf.st_mode
inside the code. But what I know is that the format of st_mode
is tricky because it has to be read as octal, convert it to int, and so on. How to compare without problem?
the format of
st_mode
is tricky because it has to be read as octal [...]
Not particularly. Just use strtoul()
with an appropriate base (8):
unsigned long mode = strtoul(argv[1], NULL, 8);
if (statbuf.st_mode == mode) {
// permissions match
}
Related Articles
Generate a valid ETAG file stream and compare with the header
How to obtain file permissions with the c ++ boost library?
How do I run Hadoop on Cygwin with the appropriate credentials to enable setting file permissions, etc.?
Obtaining a file permissions error when the cucumber-jvm.jar explodes
How to check file permissions when the netbeans php plugin downloads a file with FTP
Obtain the base URL of my server with JAX-RS
Obtaining the VB6 Application with Administrator Privileges from the Manifest
Obtain the base URL of a Play application
The file permissions were changed in the compilation process, the compilation stops because access was denied (Windows, Cygwin)
How to recover file permissions from what git & ldquo; Think & rdquo; Should the file be?
What are the correct file permissions for .gitignore
Obtain the file handle to execute the executable
Allow file file permissions in the Bash script
Are there any C APIs to extract the base file name from its full path under Linux?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK