linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: writing logfile
Date: Wed, 26 Feb 2003 11:09:15 +0100	[thread overview]
Message-ID: <20030226100914.GO7826@lug-owl.de> (raw)
In-Reply-To: <20030226092502.A12697@genestate.com>

[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]

On Wed, 2003-02-26 09:25:02 +0000, Mat Harris <mat.harris@genestate.com>
wrote in message <20030226092502.A12697@genestate.com>:
> ok i have modified it to use open, write, and close> Now tho I am getting
> garbage written to the logfile. Evidently i have made an error with types
> or there is confusion between writing a text string and writing raw bits.

Despite some other shortages, try it this way:

> On Wed, Feb 26, 2003 at 01:09:12 +0000, Glynn Clements wrote:
> int open_log()
> {
>   char logfile[4096];
>   int loghandle;
> 
>   strcpy(logfile, WEBROOT);
>   strcat(logfile, "/logs/access.log");

logfile *may* be too short. This is asking for trouble!

>   loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0600);
> 
>   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])

void
write_log(int loghandle, char *string)

> {

if(!string)
	return;

>   printf("requested file: %s\n", string);
>   write(loghandle, string, sizeof(string));
	write(loghandle, string, strlen(string));
	write(loghandle, "\n", strlen("\n"));
> }

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
       ret = do_actions((curr | FREE_SPEECH) && ~(IRAQ_WAR_2 | DRM | TCPA);

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2003-02-26 10: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
2003-02-26  9:25       ` Mat Harris
2003-02-26 10:09         ` Jan-Benedict Glaw [this message]
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=20030226100914.GO7826@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --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).