Mercurial > pidgin.yaz
comparison libpurple/core.c @ 21121:35b4f1dc4c8d
replace most calls to strerror with calls to g_strerror. strerror will return
a locale-specific string in the locale-specific encoding, which isn't
guaranteed to be UTF-8. g_strerror will always return a UTF-8 string.
I left gg and zephyr untouched, since gg doesn't include glib headers yet,
and zephyr does something weird with a #define for strerror. Someone more
familliar with those should take a look.
And the win32 guys should check and see if I screwed something up, since
they had strerror #defined to something else.
This should fix #2247 (and maybe some mystery crashes)
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 03 Nov 2007 17:52:28 +0000 |
parents | 6bf32c9e15a7 |
children | 6de09629f091 |
comparison
equal
deleted
inserted
replaced
21120:0cc12e6909e2 | 21121:35b4f1dc4c8d |
---|---|
376 char *old_name; | 376 char *old_name; |
377 #endif | 377 #endif |
378 if (g_rename(path, new_name)) | 378 if (g_rename(path, new_name)) |
379 { | 379 { |
380 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at http://developer.pidgin.im\n", | 380 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at http://developer.pidgin.im\n", |
381 path, new_name, strerror(errno)); | 381 path, new_name, g_strerror(errno)); |
382 g_free(new_name); | 382 g_free(new_name); |
383 return FALSE; | 383 return FALSE; |
384 } | 384 } |
385 g_free(new_name); | 385 g_free(new_name); |
386 | 386 |
389 new_name = g_build_filename(relative, basename, NULL); | 389 new_name = g_build_filename(relative, basename, NULL); |
390 old_name = g_build_filename(old_base, basename, NULL); | 390 old_name = g_build_filename(old_base, basename, NULL); |
391 if (symlink(new_name, old_name)) | 391 if (symlink(new_name, old_name)) |
392 { | 392 { |
393 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", | 393 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", |
394 old_name, new_name, strerror(errno)); | 394 old_name, new_name, g_strerror(errno)); |
395 } | 395 } |
396 g_free(old_name); | 396 g_free(old_name); |
397 g_free(new_name); | 397 g_free(new_name); |
398 #endif | 398 #endif |
399 | 399 |
445 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) | 445 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) |
446 { | 446 { |
447 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) | 447 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) |
448 { | 448 { |
449 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", | 449 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", |
450 user_dir, strerror(errno)); | 450 user_dir, g_strerror(errno)); |
451 g_free(status_file); | 451 g_free(status_file); |
452 g_free(old_user_dir); | 452 g_free(old_user_dir); |
453 return FALSE; | 453 return FALSE; |
454 } | 454 } |
455 } | 455 } |
457 /* This writes ~/.purple/migrating, which allows us to detect | 457 /* This writes ~/.purple/migrating, which allows us to detect |
458 * incomplete migrations and properly retry. */ | 458 * incomplete migrations and properly retry. */ |
459 if (!(fp = g_fopen(status_file, "w"))) | 459 if (!(fp = g_fopen(status_file, "w"))) |
460 { | 460 { |
461 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", | 461 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", |
462 status_file, strerror(errno)); | 462 status_file, g_strerror(errno)); |
463 g_free(status_file); | 463 g_free(status_file); |
464 g_free(old_user_dir); | 464 g_free(old_user_dir); |
465 return FALSE; | 465 return FALSE; |
466 } | 466 } |
467 fclose(fp); | 467 fclose(fp); |
515 | 515 |
516 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) | 516 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) |
517 { | 517 { |
518 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); | 518 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); |
519 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", | 519 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", |
520 name_utf8, strerror(errno)); | 520 name_utf8, g_strerror(errno)); |
521 g_free(name_utf8); | 521 g_free(name_utf8); |
522 g_free(name); | 522 g_free(name); |
523 g_dir_close(dir); | 523 g_dir_close(dir); |
524 g_free(status_file); | 524 g_free(status_file); |
525 g_free(old_user_dir); | 525 g_free(old_user_dir); |
553 * valid from ~/.purple, though it's not | 553 * valid from ~/.purple, though it's not |
554 * guaranteed. Oh well. */ | 554 * guaranteed. Oh well. */ |
555 if (symlink(link, logs_dir)) | 555 if (symlink(link, logs_dir)) |
556 { | 556 { |
557 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", | 557 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", |
558 logs_dir, link, strerror(errno)); | 558 logs_dir, link, g_strerror(errno)); |
559 g_free(link); | 559 g_free(link); |
560 g_free(name); | 560 g_free(name); |
561 g_free(logs_dir); | 561 g_free(logs_dir); |
562 g_dir_close(dir); | 562 g_dir_close(dir); |
563 g_free(status_file); | 563 g_free(status_file); |
610 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR)) | 610 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR)) |
611 { | 611 { |
612 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) | 612 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) |
613 { | 613 { |
614 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", | 614 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", |
615 new_icons_dir, strerror(errno)); | 615 new_icons_dir, g_strerror(errno)); |
616 g_free(new_icons_dir); | 616 g_free(new_icons_dir); |
617 g_dir_close(icons_dir); | 617 g_dir_close(icons_dir); |
618 g_free(name); | 618 g_free(name); |
619 g_dir_close(dir); | 619 g_dir_close(dir); |
620 g_free(status_file); | 620 g_free(status_file); |
673 FILE *new_file; | 673 FILE *new_file; |
674 | 674 |
675 if (!(fp = g_fopen(name, "rb"))) | 675 if (!(fp = g_fopen(name, "rb"))) |
676 { | 676 { |
677 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at http://developer.pidgin.im\n", | 677 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at http://developer.pidgin.im\n", |
678 name, strerror(errno)); | 678 name, g_strerror(errno)); |
679 g_free(name); | 679 g_free(name); |
680 g_dir_close(dir); | 680 g_dir_close(dir); |
681 g_free(status_file); | 681 g_free(status_file); |
682 g_free(old_user_dir); | 682 g_free(old_user_dir); |
683 return FALSE; | 683 return FALSE; |
685 | 685 |
686 new_name = g_build_filename(user_dir, entry, NULL); | 686 new_name = g_build_filename(user_dir, entry, NULL); |
687 if (!(new_file = g_fopen(new_name, "wb"))) | 687 if (!(new_file = g_fopen(new_name, "wb"))) |
688 { | 688 { |
689 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", | 689 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", |
690 new_name, strerror(errno)); | 690 new_name, g_strerror(errno)); |
691 fclose(fp); | 691 fclose(fp); |
692 g_free(new_name); | 692 g_free(new_name); |
693 g_free(name); | 693 g_free(name); |
694 g_dir_close(dir); | 694 g_dir_close(dir); |
695 g_free(status_file); | 695 g_free(status_file); |
704 | 704 |
705 size = fread(buf, 1, sizeof(buf), fp); | 705 size = fread(buf, 1, sizeof(buf), fp); |
706 if (size != sizeof(buf) && !feof(fp)) | 706 if (size != sizeof(buf) && !feof(fp)) |
707 { | 707 { |
708 purple_debug_error("core", "Error reading %s: %s. Please report this at http://developer.pidgin.im\n", | 708 purple_debug_error("core", "Error reading %s: %s. Please report this at http://developer.pidgin.im\n", |
709 name, strerror(errno)); | 709 name, g_strerror(errno)); |
710 fclose(new_file); | 710 fclose(new_file); |
711 fclose(fp); | 711 fclose(fp); |
712 g_free(new_name); | 712 g_free(new_name); |
713 g_free(name); | 713 g_free(name); |
714 g_dir_close(dir); | 714 g_dir_close(dir); |
718 } | 718 } |
719 | 719 |
720 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0) | 720 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0) |
721 { | 721 { |
722 purple_debug_error("core", "Error writing %s: %s. Please report this at http://developer.pidgin.im\n", | 722 purple_debug_error("core", "Error writing %s: %s. Please report this at http://developer.pidgin.im\n", |
723 new_name, strerror(errno)); | 723 new_name, g_strerror(errno)); |
724 fclose(new_file); | 724 fclose(new_file); |
725 fclose(fp); | 725 fclose(fp); |
726 g_free(new_name); | 726 g_free(new_name); |
727 g_free(name); | 727 g_free(name); |
728 g_dir_close(dir); | 728 g_dir_close(dir); |
733 } | 733 } |
734 | 734 |
735 if (fclose(new_file)) | 735 if (fclose(new_file)) |
736 { | 736 { |
737 purple_debug_error("core", "Error writing: %s: %s. Please report this at http://developer.pidgin.im\n", | 737 purple_debug_error("core", "Error writing: %s: %s. Please report this at http://developer.pidgin.im\n", |
738 new_name, strerror(errno)); | 738 new_name, g_strerror(errno)); |
739 } | 739 } |
740 if (fclose(fp)) | 740 if (fclose(fp)) |
741 { | 741 { |
742 purple_debug_warning("core", "Error closing %s: %s\n", | 742 purple_debug_warning("core", "Error closing %s: %s\n", |
743 name, strerror(errno)); | 743 name, g_strerror(errno)); |
744 } | 744 } |
745 g_free(new_name); | 745 g_free(new_name); |
746 } | 746 } |
747 else | 747 else |
748 purple_debug_warning("core", "Not a regular file or directory: %s\n", name); | 748 purple_debug_warning("core", "Not a regular file or directory: %s\n", name); |
752 | 752 |
753 /* The migration was successful, so delete the status file. */ | 753 /* The migration was successful, so delete the status file. */ |
754 if (g_unlink(status_file)) | 754 if (g_unlink(status_file)) |
755 { | 755 { |
756 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at http://developer.pidgin.im\n", | 756 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at http://developer.pidgin.im\n", |
757 status_file, strerror(errno)); | 757 status_file, g_strerror(errno)); |
758 g_free(status_file); | 758 g_free(status_file); |
759 return FALSE; | 759 return FALSE; |
760 } | 760 } |
761 | 761 |
762 old_icons_dir = g_build_filename(old_user_dir, "icons", NULL); | 762 old_icons_dir = g_build_filename(old_user_dir, "icons", NULL); |