UTF8 Encoding and Local Encoding question
- From: O-Zone <o-zone zerozone it>
- To: gtk-app-devel-list gnome org
- Subject: UTF8 Encoding and Local Encoding question
- Date: Mon, 26 May 2003 15:39:56 +0000
Hi all,
i've written a GTK Editor (ozeditor, http://ozeditor.zerozone.it) and, because
it use a TextBuffer, i need to convert all files in UTF8. It work *but*
sometimes g_utf8_validate write an error to strerr and not in return value of
function. Here the piece of code:
....
fread(buffer,ffs.st_size,1,ff);
#ifdef DEBUG
g_print("DEBUG: Locale to UTF8\n");
#endif
/* Converti in UTF-8 */
bbuf = g_malloc0(ffs.st_size);
memcpy(bbuf,buffer,ffs.st_size);
g_free(buffer);
buffer = g_malloc0(ffs.st_size*2);
buffer = g_locale_to_utf8(bbuf,ffs.st_size,&bread,&bwrite,&error);
g_free(bbuf);
if(error) {
g_free(buffer);
OzEDIT_ErrorDialog("Cannot convert %s to UFT8 :-( Error
%s\n",filename,error->message);
g_error_free(error);
new_object->status = OBJECT_STATUS_NEW;
new_object->type = OBJECT_TYPE_UNKNOWN;
return;
}
/* File loaded, now display it */
gtk_text_buffer_set_text(new_object->text_buffer,buffer,-1);
gtk_text_buffer_set_modified(new_object->text_buffer,FALSE);
/* Libera la memoria */
g_free(buffer);
/* Chiudi e via ! */
fclose(ff);
and with some files it LODA only the first N byes without error in
g_locale_to_utf8 !!!
Why ?
--
O-Zone !
www.zerozone.it
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]