Mercurial > pidgin.yaz
comparison src/win32/untar.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 | 59ffe137176d |
children |
comparison
equal
deleted
inserted
replaced
10588:529111933c9c | 10589:0f7452b1f777 |
---|---|
76 # include <unistd.h> | 76 # include <unistd.h> |
77 # endif | 77 # endif |
78 #endif | 78 #endif |
79 #include "debug.h" | 79 #include "debug.h" |
80 #include "untar.h" | 80 #include "untar.h" |
81 | 81 #include <glib.h> |
82 | |
83 #if GLIB_CHECK_VERSION(2,6,0) | |
84 # include <glib/gstdio.h> | |
85 #else | |
82 #define mkdir(a,b) _mkdir((a)) | 86 #define mkdir(a,b) _mkdir((a)) |
87 #define g_mkdir mkdir | |
88 #define g_fopen fopen | |
89 #define g_unlink unlink | |
90 #endif | |
91 | |
83 #define untar_error( error, args... ) gaim_debug(GAIM_DEBUG_ERROR, "untar", error, ## args ) | 92 #define untar_error( error, args... ) gaim_debug(GAIM_DEBUG_ERROR, "untar", error, ## args ) |
84 #define untar_warning( warning, args... ) gaim_debug(GAIM_DEBUG_WARNING, "untar", warning, ## args ) | 93 #define untar_warning( warning, args... ) gaim_debug(GAIM_DEBUG_WARNING, "untar", warning, ## args ) |
85 #define untar_verbose( args... ) gaim_debug(GAIM_DEBUG_INFO, "untar", ## args ) | 94 #define untar_verbose( args... ) gaim_debug(GAIM_DEBUG_INFO, "untar", ## args ) |
86 | 95 |
87 #define WSIZE 32768 /* size of decompression buffer */ | 96 #define WSIZE 32768 /* size of decompression buffer */ |
151 untar_warning("%s: exists, will not overwrite without \"FORCE option\"\n", name); | 160 untar_warning("%s: exists, will not overwrite without \"FORCE option\"\n", name); |
152 return NULL; | 161 return NULL; |
153 } | 162 } |
154 | 163 |
155 /* first try creating it the easy way */ | 164 /* first try creating it the easy way */ |
156 fp = fopen(name, CONVERT ? "w" : "wb"); | 165 fp = g_fopen(name, CONVERT ? "w" : "wb"); |
157 if (fp) | 166 if (fp) |
158 return fp; | 167 return fp; |
159 | 168 |
160 /* Else try making all of its directories, and then try creating | 169 /* Else try making all of its directories, and then try creating |
161 * the file again. | 170 * the file again. |
167 * Ignore errors for now. | 176 * Ignore errors for now. |
168 */ | 177 */ |
169 if (name[i] == '/') | 178 if (name[i] == '/') |
170 { | 179 { |
171 name[i] = '\0'; | 180 name[i] = '\0'; |
172 (void)mkdir(name, 0777); | 181 (void)g_mkdir(name, 0777); |
173 name[i] = '/'; | 182 name[i] = '/'; |
174 } | 183 } |
175 } | 184 } |
176 fp = fopen(name, CONVERT ? "w" : "wb"); | 185 fp = g_fopen(name, CONVERT ? "w" : "wb"); |
177 if (!fp) | 186 if (!fp) |
178 untar_error("Error opening: %s\n", name); | 187 untar_error("Error opening: %s\n", name); |
179 return fp; | 188 return fp; |
180 } | 189 } |
181 | 190 |
190 FILE *fpsrc; | 199 FILE *fpsrc; |
191 FILE *fpdst; | 200 FILE *fpdst; |
192 int c; | 201 int c; |
193 | 202 |
194 /* Open the source file. We do this first to make sure it exists */ | 203 /* Open the source file. We do this first to make sure it exists */ |
195 fpsrc = fopen(src, "rb"); | 204 fpsrc = g_fopen(src, "rb"); |
196 if (!fpsrc) | 205 if (!fpsrc) |
197 { | 206 { |
198 untar_error("Error opening: %s\n", src); | 207 untar_error("Error opening: %s\n", src); |
199 return; | 208 return; |
200 } | 209 } |
209 | 218 |
210 #ifdef _POSIX_SOURCE | 219 #ifdef _POSIX_SOURCE |
211 # ifndef _WEAK_POSIX | 220 # ifndef _WEAK_POSIX |
212 /* first try to link it over, instead of copying */ | 221 /* first try to link it over, instead of copying */ |
213 fclose(fpdst); | 222 fclose(fpdst); |
214 unlink(dst); | 223 g_unlink(dst); |
215 if (sym) | 224 if (sym) |
216 { | 225 { |
217 if (symlink(src, dst)) | 226 if (symlink(src, dst)) |
218 { | 227 { |
219 perror(dst); | 228 perror(dst); |
227 fclose(fpsrc); | 236 fclose(fpsrc); |
228 return; | 237 return; |
229 } | 238 } |
230 | 239 |
231 /* Dang. Reopen the destination again */ | 240 /* Dang. Reopen the destination again */ |
232 fpdst = fopen(dst, "wb"); | 241 fpdst = g_fopen(dst, "wb"); |
233 /* This *can't* fail */ | 242 /* This *can't* fail */ |
234 | 243 |
235 # endif /* _WEAK_POSIX */ | 244 # endif /* _WEAK_POSIX */ |
236 #endif /* _POSIX_SOURCE */ | 245 #endif /* _POSIX_SOURCE */ |
237 | 246 |
519 if (LISTING) | 528 if (LISTING) |
520 n2 = " directory"; | 529 n2 = " directory"; |
521 #ifdef _POSIX_SOURCE | 530 #ifdef _POSIX_SOURCE |
522 else if (mkdir(nbuf, mode) == 0) | 531 else if (mkdir(nbuf, mode) == 0) |
523 #else | 532 #else |
524 else if (mkdir(nbuf, 0755) == 0) | 533 else if (g_mkdir(nbuf, 0755) == 0) |
525 #endif | 534 #endif |
526 n2 = " created"; | 535 n2 = " created"; |
527 else | 536 else |
528 n2 = " ignored"; | 537 n2 = " ignored"; |
529 if (VERBOSE) | 538 if (VERBOSE) |
576 int ret=1; | 585 int ret=1; |
577 char curdir[_MAX_PATH]; | 586 char curdir[_MAX_PATH]; |
578 untarops = options; | 587 untarops = options; |
579 /* open the archive */ | 588 /* open the archive */ |
580 inname = filename; | 589 inname = filename; |
581 infp = fopen(filename, "rb"); | 590 infp = g_fopen(filename, "rb"); |
582 if (!infp) | 591 if (!infp) |
583 { | 592 { |
584 untar_error("Error opening: %s\n", filename); | 593 untar_error("Error opening: %s\n", filename); |
585 return 0; | 594 return 0; |
586 } | 595 } |