LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-22-2016, 12:45 AM   #1
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
C++ mkdir and Linux permissions


I just realized that the mkdir command requires me to actually set permission too. Is there a way to tell it to just use the default permissions, ex: whatever would be set if a user ran the command in the shell?

If I absolutely have to set it, what is the typical practice to do, 775?

Also, why does this command not honor the all_squash command in NFS? I'm running it over NFS, shouldn't the file have it's permission set properly by NFS?
 
Old 01-22-2016, 01:25 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
if you use C++, and you have the boost libraries, you can use them

Code:
boost::filesystem::path dir(path);
if(boost::filesystem::create_directory(dir)) {
	// ....
}
in this way you are also platform independent, (beside your path)


if not, the docu is your friend


Quote:
The argument mode specifies the mode for the new directory (see
stat(2)). It is modified by the process's umask in the usual way: in
the absence of a default ACL, the mode of the created directory is
(mode & ~umask & 0777). Whether other mode bits are honored for the
created directory depends on the operating system. For Linux, see
NOTES below.
notes can be found here
http://man7.org/linux/man-pages/man2/mkdir.2.html



from the examples :

Code:
#include <sys/types.h>
#include <sys/stat.h>

int status;
...
status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
is a good default so you can use this . umask will set the defaults than anyway for you
 
Old 01-22-2016, 01:29 AM   #3
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
Ok good to know, I'll try S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH.
 
Old 01-22-2016, 01:50 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by Red Squirrel View Post
Ok good to know, I'll try S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH.
forgotten, hava look at stat for the meanings
http://man7.org/linux/man-pages/man2/stat.2.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] mkdir: cannot creat directory. How to enable mkdir for user in usb dir? Foxbat1155 Linux - Newbie 13 02-16-2012 11:20 AM
mkdir() linux/windows vbx_wx Programming 2 03-30-2010 11:05 AM
how to give options like '-v' for mkdir using system call mkdir() ? nehapawar Linux - Newbie 2 02-05-2010 02:13 AM
mkdir in C++ setting wrong permissions fcdev Programming 4 01-13-2008 05:57 PM
MKDIR Permissions? carlosinfl Linux - General 4 05-17-2007 09:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration