open() flags

J

Jeff

Hello everybody,

I just came accross a little problem, I think the answer must be
silly, but I may as well ask. I want open() to create a file if it
does not exist, or else open it, and then for it to append text to the
end of it. Which flags would I use ? I tried (O_CREAT | O_WRONLY |
O_APPEND) but that won't work...

Any help will be appreciated,
Cheers!

- Jeff
 
J

Joona I Palaste

Jeff said:
Hello everybody,
I just came accross a little problem, I think the answer must be
silly, but I may as well ask. I want open() to create a file if it
does not exist, or else open it, and then for it to append text to the
end of it. Which flags would I use ? I tried (O_CREAT | O_WRONLY |
O_APPEND) but that won't work...
Any help will be appreciated,
Cheers!

Most like you'll be wanting comp.unix.programmer, as open() is not a
standard C function.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
 
N

nrk

Jeff said:
Hello everybody,

I just came accross a little problem, I think the answer must be
silly, but I may as well ask. I want open() to create a file if it
does not exist, or else open it, and then for it to append text to the
end of it. Which flags would I use ? I tried (O_CREAT | O_WRONLY |
O_APPEND) but that won't work...

Any help will be appreciated,
Cheers!

- Jeff
As has been mentioned, this is off-topic in this group.

<OT>
but I am curious... what exactly is errno when the open fails, and what does
perror report? One likely reason could be that you don't have proper
permissions to create or access the file (errno is EACCES then).
</OT>

-nrk.
 
J

Jeff

nrk said:
<OT>
but I am curious... what exactly is errno when the open fails, and what does
perror report? One likely reason could be that you don't have proper
permissions to create or access the file (errno is EACCES then).
</OT>

Yep that's the one. perror() prints "Permission denied", and errno is set to EACCES.

Sorry for posting on the wrong newsgroup, I will repost on comp.unix.programmer.

Cheers!

- Jeff
 
C

Christopher Benson-Manica

Jeff said:
I just came accross a little problem, I think the answer must be
silly, but I may as well ask. I want open() to create a file if it
does not exist, or else open it, and then for it to append text to the
end of it. Which flags would I use ? I tried (O_CREAT | O_WRONLY |
O_APPEND) but that won't work...

Just for laughs, what's wrong with fopen( my_file, "a" )?
 
C

CBFalconer

nrk said:
As has been mentioned, this is off-topic in this group.

<OT>
but I am curious... what exactly is errno when the open fails,
and what does perror report? One likely reason could be that

Since you obviously know it is OT, and that there is no such
function as open in standard C, why do you ask about it here? Is
this some form of dyslexia? Or possibly attention deficit
disorder? Short-term memory loss (extending over entry of two
lines!)?

The answer will help us evaluate your future posts.
 
N

nrk

CBFalconer said:
Since you obviously know it is OT, and that there is no such
function as open in standard C, why do you ask about it here? Is
this some form of dyslexia? Or possibly attention deficit
disorder? Short-term memory loss (extending over entry of two
lines!)?

The answer will help us evaluate your future posts.
I made reasonable efforts to mark the off-topic contents in my post.
Perhaps you should brush up your reading and comprehension abilities if you
failed to spot that. Thankfully, the OP engaged his brain better than
yourself and moved to a more appropriate forum to raise his question.

-nrk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,109
Messages
2,570,671
Members
47,263
Latest member
SyreetaGru

Latest Threads

Top