comparison src/util.c @ 10589:0f7452b1f777

[gaim-migrate @ 11994] Use GLib 2.6's gstdio functions. This should fix gaim not liking non-ascii filenames in win32. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 11 Feb 2005 05:10:40 +0000
parents 12349012610b
children ffabeb0fdc64
comparison
equal deleted inserted replaced
10588:529111933c9c 10589:0f7452b1f777
1926 g_strfreev(components); 1926 g_strfreev(components);
1927 g_free(dir); 1927 g_free(dir);
1928 return -1; 1928 return -1;
1929 } 1929 }
1930 1930
1931 if (mkdir(dir, mode) < 0) { 1931 if (g_mkdir(dir, mode) < 0) {
1932 gaim_debug_warning("build_dir", "mkdir: %s\n", strerror(errno)); 1932 gaim_debug_warning("build_dir", "mkdir: %s\n", strerror(errno));
1933 g_strfreev(components); 1933 g_strfreev(components);
1934 g_free(dir); 1934 g_free(dir);
1935 return -1; 1935 return -1;
1936 } 1936 }
1961 filename, user_dir); 1961 filename, user_dir);
1962 1962
1963 /* Ensure the user directory exists */ 1963 /* Ensure the user directory exists */
1964 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) 1964 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR))
1965 { 1965 {
1966 if (mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) 1966 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
1967 { 1967 {
1968 gaim_debug_error("util", "Error creating directory %s: %s\n", 1968 gaim_debug_error("util", "Error creating directory %s: %s\n",
1969 user_dir, strerror(errno)); 1969 user_dir, strerror(errno));
1970 return FALSE; 1970 return FALSE;
1971 } 1971 }
1975 filename_temp = g_strdup_printf("%s.save", filename_full); 1975 filename_temp = g_strdup_printf("%s.save", filename_full);
1976 1976
1977 /* Remove an old temporary file, if one exists */ 1977 /* Remove an old temporary file, if one exists */
1978 if (g_file_test(filename_temp, G_FILE_TEST_EXISTS)) 1978 if (g_file_test(filename_temp, G_FILE_TEST_EXISTS))
1979 { 1979 {
1980 if (unlink(filename_temp) == -1) 1980 if (g_unlink(filename_temp) == -1)
1981 { 1981 {
1982 gaim_debug_error("util", "Error removing old file %s: %s\n", 1982 gaim_debug_error("util", "Error removing old file %s: %s\n",
1983 filename_temp, strerror(errno)); 1983 filename_temp, strerror(errno));
1984 } 1984 }
1985 } 1985 }
1986 1986
1987 /* Open file */ 1987 /* Open file */
1988 file = fopen(filename_temp, "wb"); 1988 file = g_fopen(filename_temp, "wb");
1989 if (file == NULL) 1989 if (file == NULL)
1990 { 1990 {
1991 gaim_debug_error("util", "Error opening file %s for writing: %s\n", 1991 gaim_debug_error("util", "Error opening file %s for writing: %s\n",
1992 filename_temp, strerror(errno)); 1992 filename_temp, strerror(errno));
1993 g_free(filename_full); 1993 g_free(filename_full);
2018 g_free(filename_full); 2018 g_free(filename_full);
2019 g_free(filename_temp); 2019 g_free(filename_temp);
2020 return FALSE; 2020 return FALSE;
2021 } 2021 }
2022 /* Use stat to be absolutely sure. */ 2022 /* Use stat to be absolutely sure. */
2023 if ((stat(filename_temp, &st) == -1) || (st.st_size != real_size)) 2023 if ((g_stat(filename_temp, &st) == -1) || (st.st_size != real_size))
2024 { 2024 {
2025 gaim_debug_error("util", "Error writing data to file %s: " 2025 gaim_debug_error("util", "Error writing data to file %s: "
2026 "Incomplete file written; is your disk full?\n", 2026 "Incomplete file written; is your disk full?\n",
2027 filename_temp); 2027 filename_temp);
2028 g_free(filename_full); 2028 g_free(filename_full);
2038 } 2038 }
2039 2039
2040 /* Remove the old file, if it exists */ 2040 /* Remove the old file, if it exists */
2041 if (g_file_test(filename_full, G_FILE_TEST_EXISTS)) 2041 if (g_file_test(filename_full, G_FILE_TEST_EXISTS))
2042 { 2042 {
2043 if (unlink(filename_full) == -1) 2043 if (g_unlink(filename_full) == -1)
2044 { 2044 {
2045 gaim_debug_error("util", "Error removing old file %s: %s\n", 2045 gaim_debug_error("util", "Error removing old file %s: %s\n",
2046 filename_full, strerror(errno)); 2046 filename_full, strerror(errno));
2047 } 2047 }
2048 } 2048 }
2049 2049
2050 /* Rename to the REAL name */ 2050 /* Rename to the REAL name */
2051 if (rename(filename_temp, filename_full) == -1) 2051 if (g_rename(filename_temp, filename_full) == -1)
2052 { 2052 {
2053 gaim_debug_error("util", "Error renaming %s to %s: %s\n", 2053 gaim_debug_error("util", "Error renaming %s to %s: %s\n",
2054 filename_temp, filename_full, strerror(errno)); 2054 filename_temp, filename_full, strerror(errno));
2055 } 2055 }
2056 2056
2159 if( result == NULL ) 2159 if( result == NULL )
2160 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", 2160 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
2161 "Problem creating the template\n"); 2161 "Problem creating the template\n");
2162 else 2162 else
2163 { 2163 {
2164 if( (fp = fopen( result, binary?"wb+":"w+")) == NULL ) { 2164 if( (fp = g_fopen( result, binary?"wb+":"w+")) == NULL ) {
2165 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", 2165 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
2166 "Couldn't fopen() %s\n", result); 2166 "Couldn't fopen() %s\n", result);
2167 } 2167 }
2168 } 2168 }
2169 #else 2169 #else