linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn.clements@virgin.net>
To: Mat Harris <mat.harris@genestate.com>
Cc: Elias Athanasopoulos <elathan@phys.uoa.gr>,
	linux-c-programming@vger.kernel.org
Subject: Re: writing logfile
Date: Wed, 26 Feb 2003 01:09:12 +0000	[thread overview]
Message-ID: <15964.5048.368429.404765@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <20030225124937.B31033@genestate.com>


Mat Harris wrote:

>   loghandle = open(logfile, O_CREAT);

This should probably be:

   loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0600);

You may also wish to use the O_SYNC flag, to force data to be written
to disk immediately (so that it isn't lost if the system crashes or
the power fails).

As William pointed out, if you open the file with open(), you need to
use write() to write data to the file. Alternatively, you could use
fopen() and fputs(), but fopen() doesn't give you as much control
(e.g. you can't set the permissions or the O_SYNC flag on creation).

Also, you can create an ANSI stream (a "FILE *") from a descriptor
using fdopen(), and you can get the descriptor for an ANSI stream
using fileno(). But you need to be careful about accessing a file
using both methods (which basically means that you need to understand
how the two relate to each other).

-- 
Glynn Clements <glynn.clements@virgin.net>

  parent reply	other threads:[~2003-02-26  1:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-25 10:57 writing logfile Mat Harris
2003-02-25 11:38 ` Elias Athanasopoulos
2003-02-25 12:49   ` Mat Harris
2003-02-25 13:09     ` William N. Zanatta
2003-02-25 13:11       ` Mat Harris
2003-02-25 14:10       ` Elias Athanasopoulos
2003-02-25 14:18     ` Elias Athanasopoulos
2003-02-26  1:09     ` Glynn Clements [this message]
2003-02-26  9:25       ` Mat Harris
2003-02-26 10:09         ` Jan-Benedict Glaw
2003-02-26 10:18           ` Mat Harris
2003-02-26 19:45             ` Glynn Clements
2003-02-27 10:04               ` Mat Harris
2003-02-27 10:32                 ` SOLVED: " Mat Harris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15964.5048.368429.404765@cerise.nosuchdomain.co.uk \
    --to=glynn.clements@virgin.net \
    --cc=elathan@phys.uoa.gr \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=mat.harris@genestate.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).