RE: File IO???



This is what I do when I create a log file to write to:
 
  filename = g_strdup_printf("mylog.log");
  channel = g_io_channel_new_file(filename,"a+",NULL);
 
  if(channel == NULL)
    {
      g_error("failed to create new file:'%s'",filename);
      return FALSE;
    }
 
  /* start top of log */
  message = g_strdup_printf("Log started on %s at %s\n\n", datestamp(), timestamp());
 
  g_io_channel_write_chars(channel,
                           message,
                           -1,
                           &bytes,
                           NULL);
 
  /* clean up */
  g_free(message);
and when I go to clean up the channel and close the file, I use:

  /* close file */
  g_io_channel_shutdown(channel,TRUE,NULL);
Regards,
Martyn
-----Original Message-----
From: Uni [mailto:unimatrix 001 ntlworld com]
Sent: 07 February 2003 17:12
To: Russell,M,Martyn,DEN8 R
Cc: gtk-app-devel-list gnome org
Subject: Re: File IO???

Hi there,
 
Thanks very much Martyn. Yeah I've had a look at it but the "file descriptor" that is passed into the g_io_channel_unix_new kinda confuses me. Also the g_io_channel_new_file returns a GIOChannel, although hadn't I already created one using the g_io_channel_unix_new??? I'm totally lost on it all :(...
 
Thanks
Uni
 
----- Original Message -----
Sent: Friday, February 07, 2003 4:59 PM
Subject: RE: File IO???

Have you looked at GLib IOChannels?
http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html
 
Regards,
Martyn
-----Original Message-----
From: Uni [mailto:unimatrix 001 ntlworld com]
Sent: 07 February 2003 16:45
To:
gtk-app-devel-list gnome org
Subject: File IO???

Hi,
 
I'm interesting in something on File input/output with GTK+. Could anybody please point me in the direction of a tutorial or possibly give me a rough guide, as I only seem to be able to pull up the "Hello World" tutorials or the API references...
 
Thanks very much!
Uni


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]