Mercurial > pidgin.yaz
comparison libpurple/util.c @ 21136:93e674197822
merge of '8efbae676804d160b330226a663aa241a8d6a78e'
and 'ede8595c50d5172b15365ffcff7a2b7748269bc7'
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Sun, 04 Nov 2007 18:32:21 +0000 |
parents | 35b4f1dc4c8d |
children | 33da7f2a30e4 |
comparison
equal
deleted
inserted
replaced
21118:f3a995c30205 | 21136:93e674197822 |
---|---|
2503 g_free(dir); | 2503 g_free(dir); |
2504 return -1; | 2504 return -1; |
2505 } | 2505 } |
2506 | 2506 |
2507 if (g_mkdir(dir, mode) < 0) { | 2507 if (g_mkdir(dir, mode) < 0) { |
2508 purple_debug_warning("build_dir", "mkdir: %s\n", strerror(errno)); | 2508 purple_debug_warning("build_dir", "mkdir: %s\n", g_strerror(errno)); |
2509 g_strfreev(components); | 2509 g_strfreev(components); |
2510 g_free(dir); | 2510 g_free(dir); |
2511 return -1; | 2511 return -1; |
2512 } | 2512 } |
2513 } | 2513 } |
2539 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) | 2539 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) |
2540 { | 2540 { |
2541 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) | 2541 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) |
2542 { | 2542 { |
2543 purple_debug_error("util", "Error creating directory %s: %s\n", | 2543 purple_debug_error("util", "Error creating directory %s: %s\n", |
2544 user_dir, strerror(errno)); | 2544 user_dir, g_strerror(errno)); |
2545 return FALSE; | 2545 return FALSE; |
2546 } | 2546 } |
2547 } | 2547 } |
2548 | 2548 |
2549 filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename); | 2549 filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename); |
2574 { | 2574 { |
2575 if (g_unlink(filename_temp) == -1) | 2575 if (g_unlink(filename_temp) == -1) |
2576 { | 2576 { |
2577 purple_debug_error("util", "Error removing old file " | 2577 purple_debug_error("util", "Error removing old file " |
2578 "%s: %s\n", | 2578 "%s: %s\n", |
2579 filename_temp, strerror(errno)); | 2579 filename_temp, g_strerror(errno)); |
2580 } | 2580 } |
2581 } | 2581 } |
2582 | 2582 |
2583 /* Open file */ | 2583 /* Open file */ |
2584 file = g_fopen(filename_temp, "wb"); | 2584 file = g_fopen(filename_temp, "wb"); |
2585 if (file == NULL) | 2585 if (file == NULL) |
2586 { | 2586 { |
2587 purple_debug_error("util", "Error opening file %s for " | 2587 purple_debug_error("util", "Error opening file %s for " |
2588 "writing: %s\n", | 2588 "writing: %s\n", |
2589 filename_temp, strerror(errno)); | 2589 filename_temp, g_strerror(errno)); |
2590 g_free(filename_temp); | 2590 g_free(filename_temp); |
2591 return FALSE; | 2591 return FALSE; |
2592 } | 2592 } |
2593 | 2593 |
2594 /* Write to file */ | 2594 /* Write to file */ |
2597 | 2597 |
2598 /* Close file */ | 2598 /* Close file */ |
2599 if (fclose(file) != 0) | 2599 if (fclose(file) != 0) |
2600 { | 2600 { |
2601 purple_debug_error("util", "Error closing file %s: %s\n", | 2601 purple_debug_error("util", "Error closing file %s: %s\n", |
2602 filename_temp, strerror(errno)); | 2602 filename_temp, g_strerror(errno)); |
2603 g_free(filename_temp); | 2603 g_free(filename_temp); |
2604 return FALSE; | 2604 return FALSE; |
2605 } | 2605 } |
2606 | 2606 |
2607 /* Ensure the file is the correct size */ | 2607 /* Ensure the file is the correct size */ |
2629 #ifndef _WIN32 | 2629 #ifndef _WIN32 |
2630 /* Set file permissions */ | 2630 /* Set file permissions */ |
2631 if (chmod(filename_temp, S_IRUSR | S_IWUSR) == -1) | 2631 if (chmod(filename_temp, S_IRUSR | S_IWUSR) == -1) |
2632 { | 2632 { |
2633 purple_debug_error("util", "Error setting permissions of file %s: %s\n", | 2633 purple_debug_error("util", "Error setting permissions of file %s: %s\n", |
2634 filename_temp, strerror(errno)); | 2634 filename_temp, g_strerror(errno)); |
2635 } | 2635 } |
2636 #endif | 2636 #endif |
2637 | 2637 |
2638 /* Rename to the REAL name */ | 2638 /* Rename to the REAL name */ |
2639 if (g_rename(filename_temp, filename_full) == -1) | 2639 if (g_rename(filename_temp, filename_full) == -1) |
2640 { | 2640 { |
2641 purple_debug_error("util", "Error renaming %s to %s: %s\n", | 2641 purple_debug_error("util", "Error renaming %s to %s: %s\n", |
2642 filename_temp, filename_full, | 2642 filename_temp, filename_full, |
2643 strerror(errno)); | 2643 g_strerror(errno)); |
2644 } | 2644 } |
2645 | 2645 |
2646 g_free(filename_temp); | 2646 g_free(filename_temp); |
2647 | 2647 |
2648 return TRUE; | 2648 return TRUE; |
3686 | 3686 |
3687 new_data = g_try_malloc(content_len); | 3687 new_data = g_try_malloc(content_len); |
3688 if(new_data == NULL) { | 3688 if(new_data == NULL) { |
3689 purple_debug_error("util", | 3689 purple_debug_error("util", |
3690 "Failed to allocate %u bytes: %s\n", | 3690 "Failed to allocate %u bytes: %s\n", |
3691 content_len, strerror(errno)); | 3691 content_len, g_strerror(errno)); |
3692 purple_util_fetch_url_error(gfud, | 3692 purple_util_fetch_url_error(gfud, |
3693 _("Unable to allocate enough memory to hold " | 3693 _("Unable to allocate enough memory to hold " |
3694 "the contents from %s. The web server may " | 3694 "the contents from %s. The web server may " |
3695 "be trying something malicious."), | 3695 "be trying something malicious."), |
3696 gfud->website.address); | 3696 gfud->website.address); |
3724 if(len < 0) { | 3724 if(len < 0) { |
3725 if(errno == EAGAIN) { | 3725 if(errno == EAGAIN) { |
3726 return; | 3726 return; |
3727 } else { | 3727 } else { |
3728 purple_util_fetch_url_error(gfud, _("Error reading from %s: %s"), | 3728 purple_util_fetch_url_error(gfud, _("Error reading from %s: %s"), |
3729 gfud->website.address, strerror(errno)); | 3729 gfud->website.address, g_strerror(errno)); |
3730 return; | 3730 return; |
3731 } | 3731 } |
3732 } | 3732 } |
3733 | 3733 |
3734 if((len == 0) || got_eof) { | 3734 if((len == 0) || got_eof) { |
3755 | 3755 |
3756 if (len < 0 && errno == EAGAIN) | 3756 if (len < 0 && errno == EAGAIN) |
3757 return; | 3757 return; |
3758 else if (len < 0) { | 3758 else if (len < 0) { |
3759 purple_util_fetch_url_error(gfud, _("Error writing to %s: %s"), | 3759 purple_util_fetch_url_error(gfud, _("Error writing to %s: %s"), |
3760 gfud->website.address, strerror(errno)); | 3760 gfud->website.address, g_strerror(errno)); |
3761 return; | 3761 return; |
3762 } | 3762 } |
3763 gfud->request_written += len; | 3763 gfud->request_written += len; |
3764 | 3764 |
3765 if (gfud->request_written < total_len) | 3765 if (gfud->request_written < total_len) |