comparison pidgin/win32/untar.c @ 31354:4de2b3adc823

Make untarring work for non-ASCII destination dirs on Windows.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 04 Nov 2010 19:20:38 +0000
parents 99ab74fb312c
children
comparison
equal deleted inserted replaced
31338:3c1563a54785 31354:4de2b3adc823
576 /* Process an archive file. This involves reading the blocks one at a time 576 /* Process an archive file. This involves reading the blocks one at a time
577 * and passing them to a untar() function. 577 * and passing them to a untar() function.
578 */ 578 */
579 int untar(const char *filename, const char* destdir, untar_opt options) { 579 int untar(const char *filename, const char* destdir, untar_opt options) {
580 int ret=1; 580 int ret=1;
581 char curdir[_MAX_PATH]; 581 wchar_t curdir[_MAX_PATH];
582 wchar_t *w_destdir;
582 untarops = options; 583 untarops = options;
583 /* open the archive */ 584 /* open the archive */
584 inname = filename; 585 inname = filename;
585 infp = g_fopen(filename, "rb"); 586 infp = g_fopen(filename, "rb");
586 if (!infp) 587 if (!infp)
587 { 588 {
588 untar_error("Error opening: %s\n", filename); 589 untar_error("Error opening: %s\n", filename);
589 return 0; 590 return 0;
590 } 591 }
591 592
593 w_destdir = g_utf8_to_utf16(destdir, -1, NULL, NULL, NULL);
594
592 /* Set current directory */ 595 /* Set current directory */
593 if(!GetCurrentDirectory(_MAX_PATH, curdir)) { 596 if(!GetCurrentDirectoryW(_MAX_PATH, curdir)) {
594 untar_error("Could not get current directory (error %lu).\n", GetLastError()); 597 untar_error("Could not get current directory (error %lu).\n", GetLastError());
595 fclose(infp); 598 fclose(infp);
596 return 0; 599 return 0;
597 } 600 }
598 if(!SetCurrentDirectory(destdir)) { 601 if(!SetCurrentDirectoryW(w_destdir)) {
599 untar_error("Could not set current directory to (error %lu): %s\n", GetLastError(), destdir); 602 untar_error("Could not set current directory to (error %lu): %s\n", GetLastError(), destdir);
600 fclose(infp); 603 fclose(infp);
601 return 0; 604 return 0;
602 } else { 605 } else {
603 /* UNCOMPRESSED */ 606 /* UNCOMPRESSED */
612 if (outsize > 0 && ret) { 615 if (outsize > 0 && ret) {
613 untar_warning("Last file might be truncated!\n"); 616 untar_warning("Last file might be truncated!\n");
614 fclose(outfp); 617 fclose(outfp);
615 outfp = NULL; 618 outfp = NULL;
616 } 619 }
617 if(!SetCurrentDirectory(curdir)) { 620 if(!SetCurrentDirectoryW(curdir)) {
618 untar_error("Could not set current dir back to original (error %lu).\n", GetLastError()); 621 untar_error("Could not set current dir back to original (error %lu).\n", GetLastError());
619 ret=0; 622 ret=0;
620 } 623 }
621 } 624 }
622 625
626 g_free(w_destdir);
627
623 /* close the archive file. */ 628 /* close the archive file. */
624 fclose(infp); 629 fclose(infp);
625 630
626 return ret; 631 return ret;
627 } 632 }