From: Mat Harris <mat.harris@genestate.com>
To: Elias Athanasopoulos <elathan@phys.uoa.gr>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: writing logfile
Date: Tue, 25 Feb 2003 12:49:37 +0000 [thread overview]
Message-ID: <20030225124937.B31033@genestate.com> (raw)
In-Reply-To: <20030225133810.C28473@neutrino.particles.org>; from elathan@phys.uoa.gr on Tue, Feb 25, 2003 at 01:38:10 +0200
[-- Attachment #1.1: Type: text/plain, Size: 1058 bytes --]
sorry, did my special trick of not attaching the file. here it is
On Tue, Feb 25, 2003 at 01:38:10 +0200, Elias Athanasopoulos wrote:
> On Tue, Feb 25, 2003 at 10:57:40AM +0000, Mat Harris wrote:
> > in log.h and are used for opening, writing to, and closing a logfile. I have
> > attached log.h.
>
> You don't.
>
> > My questions are: How do I tell fopen to create if not there or append if
> > it is? I seem to get an error either way.
>
> This is explained in details in fopen(3).
>
> > And: Why does the fputs cause a segfault? Is there a better way of doing it?
> > I know I do not understand types and casting very well so I may have it
> > totally wrong.
>
> fputs() is not designed to segfault; you most probably use it wrong. You
> have to show parts of your code to get at least a hint.
>
> Elias
>
> --
> University of Athens I bet the human brain
> Physics Department is a kludge --Marvin Minsky
>
>
--
Mat Harris OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com www.genestate.com
[-- Attachment #1.2: log.h --]
[-- Type: text/plain, Size: 457 bytes --]
int open_log()
{
char logfile[4096];
int loghandle;
strcpy(logfile, WEBROOT);
strcat(logfile, "/logs/access.log");
loghandle = open(logfile, O_CREAT);
if (loghandle < 0)
{
fprintf(stderr, "Couldn't open logfile: %s\n", logfile);
exit(1);
}
else
{
return loghandle;
}
}
void close_log(int loghandle)
{
close(loghandle);
}
void write_log(int loghandle, char string[1024])
{
fputs(string, loghandle);
}
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
next prev parent reply other threads:[~2003-02-25 12:49 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 [this message]
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
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=20030225124937.B31033@genestate.com \
--to=mat.harris@genestate.com \
--cc=elathan@phys.uoa.gr \
--cc=linux-c-programming@vger.kernel.org \
/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).