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 07-30-2007, 05:00 AM   #1
son_t
Member
 
Registered: Sep 2006
Posts: 49

Rep: Reputation: 15
Random unix permissions with open (using C)


Hello

I use the following C code (compiled with gcc on various platforms):

outFd=open(fname,O_RDWR | O_CREAT | O_TRUNC);

to create a file to write to, and I seem to get random Unix permissions:

Code:
----r-----   1 Son  Son          1G Jul 28 09:19 12061823-Lunar_Jim.ts
--w-------   1 Son  Son       1010M Jul 28 09:04 01061822-Lunar_Jim.ts
--w-r-----   1 Son  Son        973M Jul 28 08:23 31051822-Lunar_Jim.ts
--wx------   1 Son  Son       1000M Jul 28 08:11 30051822-Lunar_Jim.ts
--wxr-----   1 Son  Son        719M Jul 27 22:10 29051827-Lunar_Jim.ts
-rwxr-----   1 Son  Son          1G Jul 27 22:01 14061822-Lunar_Jim.ts
Anyone know why this is, and how I can make the permissions more consistent?

Thanks
 
Old 07-30-2007, 05:27 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Your code is missing a third argument to the open() call, which states precisely the file permissions.
 
Old 07-30-2007, 06:35 AM   #3
son_t
Member
 
Registered: Sep 2006
Posts: 49

Original Poster
Rep: Reputation: 15
Thanks, I think this is right for RWX for user and RX for group and others?

outFd=open(fname,O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH);
 
Old 07-30-2007, 06:55 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by son_t
Thanks, I think this is right for RWX for user and RX for group and others?

outFd=open(fname,O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH);
Yes, correct.
I would do just this myself though:
Code:
outFd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0755);
(BTW what happened when you tried?)
 
Old 07-30-2007, 07:59 AM   #5
son_t
Member
 
Registered: Sep 2006
Posts: 49

Original Poster
Rep: Reputation: 15
Thanks, I didn't know you could just type the chmod octets there! It works a treat with the or-ing of the constants...
 
  


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
LXer: Speaking UNIX, Part 4: Setting and managing permissions on UNIX LXer Syndicated Linux News 0 10-21-2006 01:54 AM
random fonts appearing when I open my browser stevek10@pacbell.net Linux - Newbie 3 01-20-2006 01:13 AM
Samba and Unix permissions Dmjmusser Linux - Networking 6 01-19-2006 05:21 PM
Random windows open when I press enter in KDE pointdexter Linux - Software 0 11-12-2003 02:05 PM
unix open() question!! cybercop12us Programming 2 01-17-2003 07:50 AM

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

All times are GMT -5. The time now is 02:24 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