By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

open() flags

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jeff <ag*******@netcourrier.com> scribbled the following:
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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
Nov 13 '05 #2

P: n/a
nrk
Jeff wrote:
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.
Nov 13 '05 #3

P: n/a
nrk <ra*********@deadbeef.verizon.net> wrote in message news:<dq**************@nwrddc03.gnilink.net>...
<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
Nov 13 '05 #4

P: n/a
Jeff wrote:
Yep that's the one. perror() prints "Permission denied", and
errno is set to EACCES.


chmod might come in handy, as in chmod 644 your_file

Nov 13 '05 #5

P: n/a
Jeff <ag*******@netcourrier.com> spoke thus:
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" )?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 13 '05 #6

P: n/a
nrk wrote:
Jeff wrote:

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...

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.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #7

P: n/a
nrk
CBFalconer wrote:
nrk wrote:
Jeff wrote:
>
> 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...
>

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.

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.
Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.