Mercurial > pidgin
comparison libpurple/log.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 | 03c950701fac |
comparison
equal
deleted
inserted
replaced
21120:0cc12e6909e2 | 21121:35b4f1dc4c8d |
---|---|
754 if ((image_file = g_fopen(path, "wb")) != NULL) | 754 if ((image_file = g_fopen(path, "wb")) != NULL) |
755 { | 755 { |
756 if (!fwrite(image_data, image_byte_count, 1, image_file)) | 756 if (!fwrite(image_data, image_byte_count, 1, image_file)) |
757 { | 757 { |
758 purple_debug_error("log", "Error writing %s: %s\n", | 758 purple_debug_error("log", "Error writing %s: %s\n", |
759 path, strerror(errno)); | 759 path, g_strerror(errno)); |
760 fclose(image_file); | 760 fclose(image_file); |
761 | 761 |
762 /* Attempt to not leave half-written files around. */ | 762 /* Attempt to not leave half-written files around. */ |
763 unlink(path); | 763 unlink(path); |
764 } | 764 } |
769 } | 769 } |
770 } | 770 } |
771 else | 771 else |
772 { | 772 { |
773 purple_debug_error("log", "Unable to create file %s: %s\n", | 773 purple_debug_error("log", "Unable to create file %s: %s\n", |
774 path, strerror(errno)); | 774 path, g_strerror(errno)); |
775 } | 775 } |
776 } | 776 } |
777 | 777 |
778 /* Write the new image tag */ | 778 /* Write the new image tag */ |
779 g_string_append_printf(newmsg, "<IMG SRC=\"%s\">", new_filename); | 779 g_string_append_printf(newmsg, "<IMG SRC=\"%s\">", new_filename); |
1106 ret = g_unlink(data->path); | 1106 ret = g_unlink(data->path); |
1107 if (ret == 0) | 1107 if (ret == 0) |
1108 return TRUE; | 1108 return TRUE; |
1109 else if (ret == -1) | 1109 else if (ret == -1) |
1110 { | 1110 { |
1111 purple_debug_error("log", "Failed to delete: %s - %s\n", data->path, strerror(errno)); | 1111 purple_debug_error("log", "Failed to delete: %s - %s\n", data->path, g_strerror(errno)); |
1112 } | 1112 } |
1113 else | 1113 else |
1114 { | 1114 { |
1115 /* I'm not sure that g_unlink() will ever return | 1115 /* I'm not sure that g_unlink() will ever return |
1116 * something other than 0 or -1. -- rlaager */ | 1116 * something other than 0 or -1. -- rlaager */ |
1141 if (g_access(dirname, W_OK) == 0) | 1141 if (g_access(dirname, W_OK) == 0) |
1142 { | 1142 { |
1143 g_free(dirname); | 1143 g_free(dirname); |
1144 return TRUE; | 1144 return TRUE; |
1145 } | 1145 } |
1146 purple_debug_info("log", "access(%s) failed: %s\n", dirname, strerror(errno)); | 1146 purple_debug_info("log", "access(%s) failed: %s\n", dirname, g_strerror(errno)); |
1147 g_free(dirname); | 1147 g_free(dirname); |
1148 #else | 1148 #else |
1149 /* Unless and until someone writes equivalent win32 code, | 1149 /* Unless and until someone writes equivalent win32 code, |
1150 * we'll assume the file is deletable. */ | 1150 * we'll assume the file is deletable. */ |
1151 return TRUE; | 1151 return TRUE; |
1636 { | 1636 { |
1637 /* The index file exists and is at least as new as the log, so open it. */ | 1637 /* The index file exists and is at least as new as the log, so open it. */ |
1638 if (!(index = g_fopen(pathstr, "rb"))) | 1638 if (!(index = g_fopen(pathstr, "rb"))) |
1639 { | 1639 { |
1640 purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n", | 1640 purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n", |
1641 pathstr, strerror(errno)); | 1641 pathstr, g_strerror(errno)); |
1642 | 1642 |
1643 /* Fall through so that we'll parse the log file. */ | 1643 /* Fall through so that we'll parse the log file. */ |
1644 } | 1644 } |
1645 else | 1645 else |
1646 { | 1646 { |
1673 } | 1673 } |
1674 } | 1674 } |
1675 | 1675 |
1676 if (!(file = g_fopen(purple_stringref_value(pathref), "rb"))) { | 1676 if (!(file = g_fopen(purple_stringref_value(pathref), "rb"))) { |
1677 purple_debug_error("log", "Failed to open log file \"%s\" for reading: %s\n", | 1677 purple_debug_error("log", "Failed to open log file \"%s\" for reading: %s\n", |
1678 purple_stringref_value(pathref), strerror(errno)); | 1678 purple_stringref_value(pathref), g_strerror(errno)); |
1679 purple_stringref_unref(pathref); | 1679 purple_stringref_unref(pathref); |
1680 g_free(pathstr); | 1680 g_free(pathstr); |
1681 return NULL; | 1681 return NULL; |
1682 } | 1682 } |
1683 | 1683 |
1684 index_tmp = g_strdup_printf("%s.XXXXXX", pathstr); | 1684 index_tmp = g_strdup_printf("%s.XXXXXX", pathstr); |
1685 if ((index_fd = g_mkstemp(index_tmp)) == -1) { | 1685 if ((index_fd = g_mkstemp(index_tmp)) == -1) { |
1686 purple_debug_error("log", "Failed to open index temp file: %s\n", | 1686 purple_debug_error("log", "Failed to open index temp file: %s\n", |
1687 strerror(errno)); | 1687 g_strerror(errno)); |
1688 g_free(pathstr); | 1688 g_free(pathstr); |
1689 g_free(index_tmp); | 1689 g_free(index_tmp); |
1690 index = NULL; | 1690 index = NULL; |
1691 } else { | 1691 } else { |
1692 if ((index = fdopen(index_fd, "wb")) == NULL) | 1692 if ((index = fdopen(index_fd, "wb")) == NULL) |
1693 { | 1693 { |
1694 purple_debug_error("log", "Failed to fdopen() index temp file: %s\n", | 1694 purple_debug_error("log", "Failed to fdopen() index temp file: %s\n", |
1695 strerror(errno)); | 1695 g_strerror(errno)); |
1696 close(index_fd); | 1696 close(index_fd); |
1697 if (index_tmp != NULL) | 1697 if (index_tmp != NULL) |
1698 { | 1698 { |
1699 g_unlink(index_tmp); | 1699 g_unlink(index_tmp); |
1700 g_free(index_tmp); | 1700 g_free(index_tmp); |
1826 } | 1826 } |
1827 | 1827 |
1828 if (g_rename(index_tmp, pathstr)) | 1828 if (g_rename(index_tmp, pathstr)) |
1829 { | 1829 { |
1830 purple_debug_warning("log", "Failed to rename index temp file \"%s\" to \"%s\": %s\n", | 1830 purple_debug_warning("log", "Failed to rename index temp file \"%s\" to \"%s\": %s\n", |
1831 index_tmp, pathstr, strerror(errno)); | 1831 index_tmp, pathstr, g_strerror(errno)); |
1832 g_unlink(index_tmp); | 1832 g_unlink(index_tmp); |
1833 g_free(index_tmp); | 1833 g_free(index_tmp); |
1834 } | 1834 } |
1835 else | 1835 else |
1836 purple_debug_info("log", "Built index: %s\n", pathstr); | 1836 purple_debug_info("log", "Built index: %s\n", pathstr); |