4

Obtain the base file permissions to compare with the entry in C

 3 years ago
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.
neoserver,ios ssh client

Obtain the base file permissions to compare with the entry in C

advertisements

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

I have this etag header from the web server, ETag | 1347613725000 This is a png image, but I have no idea on how to check if the file is expired. Right now I'm hashing the stream with this code: MD5CryptoServiceProvider md5 = new MD5CryptoServiceProv

How to obtain file permissions with the c ++ boost library?

I am working on a project to make a database of the files I have on current directory. And one of the details I want about my files is the file permissions that are set with chmod in ubuntu. (just a note: I will be needing the group and owner info to

How do I run Hadoop on Cygwin with the appropriate credentials to enable setting file permissions, etc.?

I cannot change the permissions on files when I run Hadoop in Cygwin: java.io.IOException: Failed to set permissions of path: \tmp\hadoop-James\mapred\staging\James-1143336710\.staging to 0700 From what I've gathered you can't really run Cygwin as ro

Obtaining a file permissions error when the cucumber-jvm.jar explodes

I am trying to create an executable jar for functional tests by exploding the dependency jars, using gradle task of type Jar. Cucumber-1.1.3 is one of the dependencies. I am using gradle 1.1 with JVM 1.6 (company standards) I get the following error

How to check file permissions when the netbeans php plugin downloads a file with FTP

Whenever netbeans preforms an ftp upload the files are uploaded with the permissions set to 640. This causes PHP to throw the following error: Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Faile

Obtain the base URL of my server with JAX-RS

How do I get the base url of my server with JAX-RS? Basically I want ""http://localhost:8080/.." when the program is on localhost and "http://www.theSite.com/..." when the program is on a live server. I am using Jersey Framework.Y

Obtaining the VB6 Application with Administrator Privileges from the Manifest

I have a VB6 app that manipulates files in ProgramData folder Win7. It does fine with files that it creates but any files that were initially installed, it cannot delete. I feel there may be more issues unless the program can run as administrator. I

Obtain the base URL of a Play application

I want to obtain the current base url of an application which usually http://localhost:9000/ at localhost and http://mydomain.com at a server. If the future I might start using https. How can I do this?What version of Play Framework are you using ? I

The file permissions were changed in the compilation process, the compilation stops because access was denied (Windows, Cygwin)

I'm trying to build ArangoDB using the official build scripts and following the official Windows build instructions. Multiple steps in the build process seem to mess around with file permissions, so that compilations fail, because required files can'

How to recover file permissions from what git & ldquo; Think & rdquo; Should the file be?

I have a git checkout. All the file permissions are different than what git thinks they should be therefore they all show up as modified. Without touching the content of the files (just want to modify the permissions) how do I set all the files permi

What are the correct file permissions for .gitignore

I'm about to work on a new project and the .gitignore file is accessible to the web which is a bit of a security leak. The .gitignore files permissions are 644 i.e. -rw-r--r--. The project is on bitbucket.org, perhaps this requires the file to be acc

Obtain the file handle to execute the executable

I am trying to call GetFileInformationByHandle on the executable of my own running program. This means I'll need to get a file handle to the .exe that started my program. Is there any way to do this? Failing that, is there any way to get the nFileInd

Allow file file permissions in the Bash script

I'm having trouble reading the permissions of file arguments. I looks like it has something to do with hidden files but I'm not sure why. Current Code: #!/bin/bash if [ $# = 0 ] then echo "Usage ./checkPerm filename [filename2 ... filenameN]" ex

Are there any C APIs to extract the base file name from its full path under Linux?

Given the full path, the API should give me the base file name. E.g., "/foo/bar.txt" --> "bar.txt".There's basename() . Feed it with a path (in the form of a char*) and it will return you the base name (that is the name of the file/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK