Dir creating, permissions setting issue!

Reply

Join Date: Sep 2007
Posts: 38
Reputation: BigFormat is an unknown quantity at this point 
Solved Threads: 0
BigFormat BigFormat is offline Offline
Light Poster

Dir creating, permissions setting issue!

 
0
  #1
Nov 25th, 2008
Hello, I need to create some dirs (one for each user), taking the dir name from a given string.
I managed to do this with the following code:

  1. DIR *dir_ptr;
  2. char *target_dir;
  3.  
  4. target_dir = malloc(32*sizeof(char));
  5.  
  6. for(all users) {
  7.  
  8. /* Set username for current user */
  9.  
  10. target_dir[0] = '\0';
  11. strcat(target_dir, "./Environment");
  12. strcat(target_dir, "/");
  13. strcat(target_dir, username);
  14. strcat(target_dir, "/");
  15.  
  16. /* check for DIR existence, if not, create */
  17. if((dir_ptr = opendir(target_dir)) == NULL)
  18. mkdir(target_dir);
  19.  
  20. }

My problem is these dirs are created with no permissions at all, I've got to set them manually doing "chmod 777 name", is there a function out there to create dirs with permissions already setted? I need to use them later from inside my application and I want the users to be able to modify them from the OS (ie adding files inside).
I use Debian, in XP no problems!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Dir creating, permissions setting issue!

 
0
  #2
Nov 25th, 2008
Apparently, mkdir() takes 2 parameters.
http://www.rocketaware.com/man/man2/mkdir.2.htm

One wonders whether
- you read the manual before calling it
- included the appropriate header file which would have warned you about too few parameters
- mis-took early success on other platforms as a sign of bug-free code.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC