g_locale_to_utf8 with more than 64KB ASCII file



hi,
I need help converting locale files to utf8:

int
app_open (GtkWidget *widget, const char *file_name)
{
 int fd;
 int rc;
 struct stat fdst;
 void *reg;

 fd = open (file_name, O_RDONLY, 0);
 if (fd != -1)
 {
   if (fstat (fd, &fdst) != -1)
   {
     reg = mmap (0, fdst.st_size, PROT_READ, MAP_SHARED, fd, 0);
     if (reg != (caddr_t)-1)
     {
       GtkWidget *view;
       GtkTextBuffer *buffer;
       GtkTextIter start, end;
       gchar *utf8_buffer = 0;

       view = lookup_widget (widget, "text_view");
       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

       gtk_text_buffer_get_bounds (buffer, &start, &end);
       gtk_text_buffer_delete (buffer, &start, &end);

utf8_buffer = g_locale_to_utf8 (reg, fdst.st_size, NULL, NULL, NULL);
       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &start);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &start, utf8_buffer, -1);

       g_free (utf8_buffer);

       munmap (reg, fdst.st_size);
       rc = 1;
     }
     else
     {
       rc = 0;
     }
   }
   else
   {
     rc = 0;
   }

   close (fd);
 }
 else
 {
rc = 0; }

 return rc;
}

if the file is 64KB or more? how can I read 1KB, convert it, fill GtkTextBuffer and then read net 1KB until the end of file using mmap and g_locale_to_utf8?

thanks,
andrew





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