Ticket #4160: Transmission-r12283.diff
File Transmission-r12283.diff, 57.8 KB (added by jordan, 12 years ago) |
---|
-
libtransmission/utils.c
241 241 va_end( args ); 242 242 evbuffer_add_printf( buf, " (%s:%d)\n", base, line ); 243 243 /* FIXME(libevent2) ifdef this out for nonwindows platforms */ 244 OutputDebugString ( evbuffer_pullup( buf, -1 ) );244 OutputDebugStringA( evbuffer_pullup( buf, -1 ) ); 245 245 if( fp ) 246 246 fputs( (const char*)evbuffer_pullup( buf, -1 ), fp ); 247 247 … … 271 271 evutil_vsnprintf( buf, sizeof( buf ), fmt, ap ); 272 272 va_end( ap ); 273 273 274 OutputDebugString ( buf );274 OutputDebugStringA( buf ); 275 275 276 276 if( *buf ) 277 277 { … … 430 430 size_t * size ) 431 431 { 432 432 uint8_t * buf; 433 struct statsb;433 STAT sb; 434 434 int fd; 435 435 ssize_t n; 436 436 const char * const err_fmt = _( "Couldn't read \"%1$s\": %2$s" ); 437 437 438 438 /* try to stat the file */ 439 439 errno = 0; 440 if( stat( path, &sb ) )440 if( tr_stati64( path, &sb ) ) 441 441 { 442 442 const int err = errno; 443 443 tr_dbg( err_fmt, path, tr_strerror( errno ) ); … … 516 516 #ifdef WIN32 517 517 if( path && isalpha( path[0] ) && path[1] == ':' && !path[2] ) 518 518 return 0; 519 return mkdir( path ); 519 if (path) { 520 int n = strlen(path) + 1; 521 wchar_t pathUTF16[n]; 522 if (MultiByteToWideChar(CP_UTF8, 0, path, -1, pathUTF16, n)) 523 return _wmkdir(pathUTF16); 524 } 525 errno = ENOENT; 526 return -1; 520 527 #else 521 528 return mkdir( path, permissions ); 522 529 #endif … … 528 535 { 529 536 char * path = tr_strdup( path_in ); 530 537 char * p, * pp; 531 struct statsb;538 STAT sb; 532 539 int done; 533 540 534 541 /* walk past the root */ … … 546 553 else 547 554 *p = '\0'; 548 555 549 if( stat( path, &sb ) )556 if( tr_stati64( path, &sb ) ) 550 557 { 551 558 /* Folder doesn't exist yet */ 552 559 if( tr_mkdir( path, permissions ) ) … … 1472 1479 int in; 1473 1480 int out; 1474 1481 char * buf; 1475 struct statst;1482 STAT st; 1476 1483 off_t bytesLeft; 1477 1484 const size_t buflen = 1024 * 128; /* 128 KiB buffer */ 1478 1485 1479 1486 /* make sure the old file exists */ 1480 if( stat( oldpath, &st ) ) {1487 if( tr_stati64( oldpath, &st ) ) { 1481 1488 const int err = errno; 1482 1489 errno = err; 1483 1490 return -1; … … 1499 1506 1500 1507 /* they might be on the same filesystem... */ 1501 1508 { 1502 const int i = rename( oldpath, newpath );1509 const int i = tr_rename( oldpath, newpath ); 1503 1510 if( renamed != NULL ) 1504 1511 *renamed = i == 0; 1505 1512 if( !i ) … … 1530 1537 if( bytesLeft != 0 ) 1531 1538 return -1; 1532 1539 1533 unlink( oldpath );1540 tr_unlink( oldpath ); 1534 1541 return 0; 1535 1542 } 1536 1543 1537 1544 bool 1538 1545 tr_is_same_file( const char * filename1, const char * filename2 ) 1539 1546 { 1540 struct stat sb1, sb2; 1547 #ifdef WIN32 /* no inodes on Windows */ 1548 bool res; 1549 HANDLE fh1, fh2; 1550 BY_HANDLE_FILE_INFORMATION fi1, fi2; 1551 int n = strlen(filename1) + 1; 1552 int m = strlen(filename2) + 1; 1553 wchar_t f1nameUTF16[n]; 1554 wchar_t f2nameUTF16[m]; 1541 1555 1542 return !stat( filename1, &sb1 ) 1543 && !stat( filename2, &sb2 ) 1556 MultiByteToWideChar(CP_UTF8, 0, filename1, -1, f1nameUTF16, n); 1557 MultiByteToWideChar(CP_UTF8, 0, filename2, -1, f2nameUTF16, m); 1558 fh1 = CreateFileW(f1nameUTF16, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 1559 fh2 = CreateFileW(f2nameUTF16, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 1560 res = GetFileInformationByHandle( fh1, &fi1 ) 1561 && GetFileInformationByHandle( fh2, &fi2 ) 1562 && ( fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber ) 1563 && ( fi1.nFileIndexHigh == fi2.nFileIndexHigh ) 1564 && ( fi1.nFileIndexLow == fi2.nFileIndexLow ); 1565 CloseHandle(fh1); 1566 CloseHandle(fh2); 1567 return res; 1568 #else 1569 STAT sb1, sb2; 1570 1571 return !tr_stati64( filename1, &sb1 ) 1572 && !tr_stati64( filename2, &sb2 ) 1544 1573 && ( sb1.st_dev == sb2.st_dev ) 1545 1574 && ( sb1.st_ino == sb2.st_ino ); 1575 #endif 1546 1576 } 1547 1577 1548 1578 /*** 1549 1579 **** 1550 1580 ***/ 1551 1581 1582 /* getpagesize for windows */ 1583 static long 1584 getpagesize( void ) 1585 { 1586 static long g_pagesize = 0; 1587 1588 if( !g_pagesize ) 1589 { 1590 SYSTEM_INFO system_info; 1591 GetSystemInfo ( &system_info ); 1592 g_pagesize = system_info.dwPageSize; 1593 } 1594 return g_pagesize; 1595 } 1596 1552 1597 void* 1553 1598 tr_valloc( size_t bufLen ) 1554 1599 { … … 1583 1628 return buf; 1584 1629 } 1585 1630 1631 #ifdef WIN32 1632 /* From: 1633 * "Obtaining a File Name From a File Handle" 1634 * http://msdn.microsoft.com/en-us/library/aa366789.aspx 1635 * See also: 1636 * "GetFinalPathNameByHandle Function" (for Vista or newer) 1637 * http://msdn.microsoft.com/en-us/library/aa364962%28v=vs.85%29.aspx 1638 * Note: 1639 * GetFileNameFromHandleW only works with files (not directories). 1640 */ 1641 #include <psapi.h> /* needs linking with -lpsapi */ 1642 1643 static 1644 bool GetFileNameFromHandleW(HANDLE hFile, 1645 wchar_t *filePath, 1646 DWORD filePathSize) 1647 { 1648 bool bSuccess = FALSE; 1649 HANDLE hFileMap; 1650 1651 // Get the file size. 1652 DWORD dwFileSizeHi = 0; 1653 DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi); 1654 1655 if( dwFileSizeLo == 0 && dwFileSizeHi == 0 ) 1656 { 1657 /* error "Cannot map a file with a length of zero.\n" */ 1658 return FALSE; 1659 } 1660 1661 // Create a file mapping object. 1662 hFileMap = CreateFileMapping(hFile, 1663 NULL, 1664 PAGE_READONLY, 1665 0, 1666 1, 1667 NULL); 1668 1669 if (hFileMap) 1670 { 1671 // Create a file mapping to get the file name. 1672 void* pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1); 1673 1674 if (pMem) 1675 { 1676 if (GetMappedFileName (GetCurrentProcess(), 1677 pMem, 1678 filePath, 1679 filePathSize)) 1680 { 1681 // Translate path with device name to drive letters. 1682 wchar_t szTemp[MAX_PATH + 1]; 1683 szTemp[0] = '\0'; 1684 1685 if (GetLogicalDriveStringsW(MAX_PATH, szTemp)) 1686 { 1687 wchar_t szName[MAX_PATH + 1]; 1688 wchar_t szDrive[3] = L" :"; 1689 bool bFound = FALSE; 1690 wchar_t * p = szTemp; 1691 1692 do 1693 { 1694 // Copy the drive letter to the template string 1695 *szDrive = *p; 1696 1697 // Look up each device name 1698 if (QueryDosDevice(szDrive, szName, MAX_PATH)) 1699 { 1700 size_t uNameLen = wcslen(szName); 1701 1702 if (uNameLen < MAX_PATH) 1703 { 1704 bFound = _wcsnicmp(filePath, szName, uNameLen) == 0; 1705 1706 if (bFound && *(filePath + uNameLen) == L'\\') 1707 { 1708 // Reconstruct filePath using szTempFile 1709 // Replace device path with DOS path 1710 wchar_t szTempFile[MAX_PATH + 1]; 1711 _snwprintf( szTempFile, 1712 MAX_PATH, 1713 L"%s%s", 1714 szDrive, 1715 filePath + uNameLen); 1716 wcsncpy(filePath, szTempFile, wcslen(szTempFile)); 1717 filePath[wcslen(szTempFile)] = L'\0'; 1718 } 1719 } 1720 } 1721 1722 // Go to the next NULL character. 1723 while (*p++); 1724 } while (!bFound && *p); // end of string 1725 } 1726 } 1727 bSuccess = TRUE; 1728 UnmapViewOfFile(pMem); 1729 } 1730 CloseHandle(hFileMap); 1731 } 1732 return(bSuccess); 1733 } 1734 #endif 1735 1586 1736 char * 1587 1737 tr_realpath( const char * path, char * resolved_path ) 1588 1738 { 1589 1739 #ifdef WIN32 1590 /* From a message to the Mingw-msys list, Jun 2, 2005 by Mark Junker. */ 1591 if( GetFullPathNameA( path, TR_PATH_MAX, resolved_path, NULL ) == 0 ) 1740 HANDLE hFile; 1741 wchar_t pathUTF16[MAX_PATH+1]; 1742 1743 MultiByteToWideChar(CP_UTF8, 0, path, -1, pathUTF16, MAX_PATH+1); 1744 hFile = CreateFileW(pathUTF16, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 1745 if(hFile == INVALID_HANDLE_VALUE) 1592 1746 return NULL; 1747 if( !GetFileNameFromHandleW( hFile, pathUTF16, MAX_PATH ) ) 1748 return CloseHandle(hFile), NULL; 1749 if (!resolved_path) 1750 resolved_path = malloc(MAX_PATH + 1); 1751 WideCharToMultiByte(CP_UTF8, 0, pathUTF16, -1, resolved_path, MAX_PATH+1, NULL, NULL); 1752 CloseHandle(hFile); 1593 1753 return resolved_path; 1594 1754 #else 1595 1755 return realpath( path, resolved_path ); -
libtransmission/blocklist.c
37 37 #include "blocklist.h" 38 38 #include "net.h" 39 39 #include "utils.h" 40 #include "platform.h" 40 41 41 42 #ifndef O_BINARY 42 43 #define O_BINARY 0 … … 56 57 struct tr_blocklist 57 58 { 58 59 bool isEnabled; 60 #ifdef WIN32 61 HANDLE fd; 62 #else 59 63 int fd; 64 #endif 60 65 size_t ruleCount; 61 66 size_t byteCount; 62 67 char * filename; 63 68 struct tr_ipv4_range * rules; 64 69 }; 65 70 71 #ifdef WIN32 72 static HANDLE fh; 73 #endif 74 66 75 static void 67 76 blocklistClose( tr_blocklist * b ) 68 77 { 69 78 if( b->rules ) 70 79 { 80 #ifdef WIN32 81 UnmapViewOfFile( b->rules ); 82 CloseHandle( fh ); 83 CloseHandle( b->fd ); 84 b->fd = NULL; 85 #else 71 86 munmap( b->rules, b->byteCount ); 72 87 close( b->fd ); 88 b->fd = -1; 89 #endif 73 90 b->rules = NULL; 74 91 b->ruleCount = 0; 75 92 b->byteCount = 0; 76 b->fd = -1;77 93 } 78 94 } 79 95 80 96 static void 81 97 blocklistLoad( tr_blocklist * b ) 82 98 { 99 #ifdef WIN32 100 HANDLE fd; 101 wchar_t *nameUTF16; 102 int n; 103 #else 83 104 int fd; 105 #endif 84 106 size_t byteCount; 85 struct statst;107 STAT st; 86 108 const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" ); 87 109 88 110 blocklistClose( b ); 89 111 90 if( stat( b->filename, &st ) == -1 )112 if( tr_stati64( b->filename, &st ) == -1 ) 91 113 return; 92 114 93 fd = open( b->filename, O_RDONLY | O_BINARY ); 115 byteCount = (size_t) st.st_size; 116 117 #ifdef WIN32 118 n = strlen(b->filename) + 1; 119 nameUTF16 = malloc(n); 120 MultiByteToWideChar(CP_UTF8, 0, b->filename, -1, nameUTF16, n); 121 fd = CreateFileW( nameUTF16, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 ); 122 fh = CreateFileMapping( fd, NULL, PAGE_READONLY, 0, byteCount, NULL); 123 free(nameUTF16); 124 if ( fh != NULL ) 125 b->rules = MapViewOfFile( fh, FILE_MAP_READ, 0, 0, 0 ); 126 else 127 b->rules = NULL; 128 #else 129 fd = tr_open( b->filename, O_RDONLY | O_BINARY ); 94 130 if( fd == -1 ) 95 131 { 96 132 tr_err( err_fmt, b->filename, tr_strerror( errno ) ); 97 133 return; 98 134 } 99 135 100 byteCount = (size_t) st.st_size;101 136 b->rules = mmap( NULL, byteCount, PROT_READ, MAP_PRIVATE, fd, 0 ); 137 #endif 102 138 if( !b->rules ) 103 139 { 104 140 tr_err( err_fmt, b->filename, tr_strerror( errno ) ); 141 #ifdef WIN32 142 CloseHandle( fd ); 143 #else 105 144 close( fd ); 145 #endif 106 146 return; 107 147 } 108 148 … … 140 180 blocklistDelete( tr_blocklist * b ) 141 181 { 142 182 blocklistClose( b ); 143 unlink( b->filename );183 tr_unlink( b->filename ); 144 184 } 145 185 146 186 /*** … … 153 193 tr_blocklist * b; 154 194 155 195 b = tr_new0( tr_blocklist, 1 ); 196 #ifdef WIN32 197 b->fd = NULL; 198 #else 156 199 b->fd = -1; 200 #endif 157 201 b->filename = tr_strdup( filename ); 158 202 b->isEnabled = isEnabled; 159 203 … … 177 221 int 178 222 _tr_blocklistExists( const tr_blocklist * b ) 179 223 { 180 struct statst;224 STAT st; 181 225 182 return ! stat( b->filename, &st );226 return !tr_stati64( b->filename, &st ); 183 227 } 184 228 185 229 int … … 333 377 return 0; 334 378 } 335 379 336 in = fopen( filename, "rb" );380 in = tr_fopen( filename, "rb" ); 337 381 if( !in ) 338 382 { 339 383 tr_err( err_fmt, filename, tr_strerror( errno ) ); … … 342 386 343 387 blocklistClose( b ); 344 388 345 out = fopen( b->filename, "wb+" );389 out = tr_fopen( b->filename, "wb+" ); 346 390 if( !out ) 347 391 { 348 392 tr_err( err_fmt, b->filename, tr_strerror( errno ) ); -
libtransmission/bencode.c
20 20 21 21 #ifdef WIN32 /* tr_mkstemp() */ 22 22 #include <fcntl.h> 23 # define _S_IREAD 25624 # define _S_IWRITE 12823 #include <share.h> 24 #include <sys/stat.h> 25 25 #endif 26 26 27 27 #include <locale.h> /* setlocale() */ … … 1651 1651 tr_mkstemp( char * template ) 1652 1652 { 1653 1653 #ifdef WIN32 1654 int n = strlen(template) + 1; 1654 1655 const int flags = O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED; 1655 1656 const mode_t mode = _S_IREAD | _S_IWRITE; 1656 mktemp( template ); 1657 return open( template, flags, mode ); 1657 wchar_t templateUTF16[n]; 1658 if (MultiByteToWideChar(CP_UTF8, 0, template, -1, templateUTF16, n)) 1659 { 1660 _wmktemp(templateUTF16); 1661 WideCharToMultiByte(CP_UTF8, 0, templateUTF16, -1, template, n, NULL, NULL); 1662 return _wopen(templateUTF16, flags, mode); 1663 } 1664 errno = EINVAL; 1665 return -1; 1658 1666 #else 1659 1667 return mkstemp( template ); 1660 1668 #endif … … 1703 1711 { 1704 1712 tr_err( _( "Couldn't save temporary file \"%1$s\": %2$s" ), tmp, tr_strerror( err ) ); 1705 1713 tr_close_file( fd ); 1706 unlink( tmp );1714 tr_unlink( tmp ); 1707 1715 } 1708 1716 else 1709 1717 { 1710 1718 //tr_fsync( fd ); 1711 1719 tr_close_file( fd ); 1712 1713 #ifdef WIN32 1714 if( MoveFileEx( tmp, filename, MOVEFILE_REPLACE_EXISTING ) ) 1715 #else 1716 if( !rename( tmp, filename ) ) 1717 #endif 1720 if( !tr_rename( tmp, filename ) ) 1718 1721 { 1719 1722 tr_inf( _( "Saved \"%s\"" ), filename ); 1720 1723 } … … 1722 1725 { 1723 1726 err = errno; 1724 1727 tr_err( _( "Couldn't save file \"%1$s\": %2$s" ), filename, tr_strerror( err ) ); 1725 unlink( tmp );1728 tr_unlink( tmp ); 1726 1729 } 1727 1730 } 1728 1731 } -
libtransmission/metainfo.c
65 65 { 66 66 int i; 67 67 char * path; 68 struct statsb;68 STAT sb; 69 69 const int tagCount = 5; 70 70 const char * tags[] = { "beos", "cli", "daemon", "macosx", "wx" }; 71 71 72 72 /* test the beos, cli, daemon, macosx, wx tags */ 73 73 for( i=0; i<tagCount; ++i ) { 74 74 path = tr_strdup_printf( "%s%c%s-%s", tr_getTorrentDir( session ), '/', inf->hashString, tags[i] ); 75 if( ! stat( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) )75 if( !tr_stati64( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) ) 76 76 return path; 77 77 tr_free( path ); 78 78 } 79 79 80 80 /* test a non-tagged file */ 81 81 path = tr_buildPath( tr_getTorrentDir( session ), inf->hashString, NULL ); 82 if( ! stat( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) )82 if( !tr_stati64( path, &sb ) && ( ( sb.st_mode & S_IFMT ) == S_IFREG ) ) 83 83 return path; 84 84 tr_free( path ); 85 85 … … 94 94 tr_metainfoMigrate( tr_session * session, 95 95 tr_info * inf ) 96 96 { 97 struct statnew_sb;97 STAT new_sb; 98 98 char * name = getTorrentFilename( session, inf ); 99 99 100 if( stat( name, &new_sb ) || ( ( new_sb.st_mode & S_IFMT ) != S_IFREG ) )100 if( tr_stati64( name, &new_sb ) || ( ( new_sb.st_mode & S_IFMT ) != S_IFREG ) ) 101 101 { 102 102 char * old_name = getOldTorrentFilename( session, inf ); 103 103 size_t contentLen; … … 108 108 { 109 109 FILE * out; 110 110 errno = 0; 111 out = fopen( name, "wb+" );111 out = tr_fopen( name, "wb+" ); 112 112 if( !out ) 113 113 { 114 114 tr_nerr( inf->name, _( "Couldn't create \"%1$s\": %2$s" ), … … 122 122 tr_free( inf->torrent ); 123 123 inf->torrent = tr_strdup( name ); 124 124 tr_sessionSetTorrentFile( session, inf->hashString, name ); 125 unlink( old_name );125 tr_unlink( old_name ); 126 126 } 127 127 fclose( out ); 128 128 } … … 590 590 char * filename; 591 591 592 592 filename = getTorrentFilename( session, inf ); 593 unlink( filename );593 tr_unlink( filename ); 594 594 tr_free( filename ); 595 595 596 596 filename = getOldTorrentFilename( session, inf ); 597 unlink( filename );597 tr_unlink( filename ); 598 598 tr_free( filename ); 599 599 } -
libtransmission/rpcimpl.c
1179 1179 tr_close_file( fd ); 1180 1180 } 1181 1181 1182 unlink( filename );1182 tr_unlink( filename ); 1183 1183 tr_free( filename ); 1184 1184 filename = filename2; 1185 1185 } … … 1192 1192 tr_snprintf( result, sizeof( result ), "success" ); 1193 1193 } 1194 1194 1195 unlink( filename );1195 tr_unlink( filename ); 1196 1196 tr_free( filename ); 1197 1197 } 1198 1198 -
libtransmission/announcer-udp.c
13 13 #define __LIBTRANSMISSION_ANNOUNCER_MODULE___ 14 14 15 15 #include <string.h> /* memcpy(), memset() */ 16 #include <errno.h> 16 17 17 18 #include <event2/buffer.h> 18 19 #include <event2/dns.h> -
libtransmission/fdlimit.c
52 52 #include "net.h" 53 53 #include "session.h" 54 54 #include "torrent.h" /* tr_isTorrent() */ 55 #include "platform.h" 55 56 56 57 #define dbgmsg( ... ) \ 57 58 do { \ … … 107 108 108 109 #ifdef WIN32 109 110 110 HANDLE hFile = CreateFile( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0 ); 111 if( hFile != INVALID_HANDLE_VALUE ) 111 int n = strlen(filename) + 1; 112 wchar_t filenameUTF16[n]; 113 HANDLE hFile; 114 if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameUTF16, n)) 112 115 { 113 LARGE_INTEGER li; 114 li.QuadPart = length; 115 success = SetFilePointerEx( hFile, li, NULL, FILE_BEGIN ) && SetEndOfFile( hFile ); 116 CloseHandle( hFile ); 116 hFile = CreateFileW( filenameUTF16, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0 ); 117 if( hFile != INVALID_HANDLE_VALUE ) 118 { 119 LARGE_INTEGER li; 120 li.QuadPart = length; 121 success = SetFilePointerEx( hFile, li, NULL, FILE_BEGIN ) 122 && SetEndOfFile( hFile ); 123 /* && SetFileValidData( hFile, length );*/ 124 CloseHandle( hFile ); 125 } 117 126 } 118 127 119 128 #else 120 129 121 130 int flags = O_RDWR | O_CREAT | O_LARGEFILE; 122 int fd = open( filename, flags, 0666 );131 int fd = tr_open( filename, flags, 0666 ); 123 132 if( fd >= 0 ) 124 133 { 125 134 # ifdef HAVE_FALLOCATE64 … … 276 285 static int 277 286 open_local_file( const char * filename, int flags ) 278 287 { 279 const int fd = open( filename, flags, 0666 );288 const int fd = tr_open( filename, flags, 0666 ); 280 289 tr_set_file_for_single_pass( fd ); 281 290 return fd; 282 291 } … … 355 364 uint64_t file_size ) 356 365 { 357 366 int flags; 358 struct statsb;367 STAT sb; 359 368 bool alreadyExisted; 360 369 361 370 /* confirm that existing_dir, if specified, exists on the disk */ 362 if( existing_dir && *existing_dir && stat( existing_dir, &sb ) )371 if( existing_dir && *existing_dir && tr_stati64( existing_dir, &sb ) ) 363 372 { 364 373 const int err = errno; 365 374 tr_err( _( "Couldn't open \"%1$s\": %2$s" ), existing_dir, tr_strerror( err ) ); … … 379 388 tr_free( dir ); 380 389 } 381 390 382 alreadyExisted = ! stat( filename, &sb ) && S_ISREG( sb.st_mode );391 alreadyExisted = !tr_stati64( filename, &sb ) && S_ISREG( sb.st_mode ); 383 392 384 393 if( writable && !alreadyExisted && ( allocation == TR_PREALLOCATE_FULL ) ) 385 394 if( preallocate_file_full( filename, file_size ) ) … … 388 397 /* open the file */ 389 398 flags = writable ? ( O_RDWR | O_CREAT ) : O_RDONLY; 390 399 flags |= O_LARGEFILE | O_BINARY | O_SEQUENTIAL; 391 o->fd = open( filename, flags, 0666 );400 o->fd = tr_open( filename, flags, 0666 ); 392 401 393 402 if( o->fd == -1 ) 394 403 { -
libtransmission/fdlimit.h
16 16 17 17 #include "transmission.h" 18 18 #include "net.h" 19 #ifdef WIN32 20 #include <sys/types.h> /* ssize_t, off_t */ 21 #endif 19 22 20 23 /** 21 24 * @addtogroup file_io File IO -
libtransmission/tr-dht.c
122 122 123 123 rc = getaddrinfo(name, pp, &hints, &info); 124 124 if(rc != 0) { 125 tr_nerr("DHT", "%s:%s: %s", name, pp, gai_strerror (rc));125 tr_nerr("DHT", "%s:%s: %s", name, pp, gai_strerrorA(rc)); 126 126 return; 127 127 } 128 128 … … 200 200 tr_buildPath(cl->session->configDir, "dht.bootstrap", NULL); 201 201 202 202 if(bootstrap_file) 203 f = fopen(bootstrap_file, "rb");203 f = tr_fopen(bootstrap_file, "rb"); 204 204 if(f != NULL) { 205 205 tr_ninf("DHT", "Attempting manual bootstrap"); 206 206 for(;;) { -
libtransmission/torrent-magnet.c
26 26 #include "torrent-magnet.h" 27 27 #include "utils.h" 28 28 #include "web.h" 29 #include "platform.h" 29 30 30 31 #define dbgmsg( tor, ... ) \ 31 32 do { \ … … 161 162 assert( tor->infoDictLength > 0 ); 162 163 assert( tor->infoDictOffset >= 0 ); 163 164 164 fp = fopen( tor->info.torrent, "rb" );165 fp = tr_fopen( tor->info.torrent, "rb" ); 165 166 if( fp != NULL ) 166 167 { 167 168 const int o = piece * METADATA_PIECE_SIZE; … … 259 260 int infoDictLength; 260 261 261 262 /* remove any old .torrent and .resume files */ 262 remove( path );263 tr_remove( path ); 263 264 tr_torrentRemoveResume( tor ); 264 265 265 266 dbgmsg( tor, "Saving completed metadata to \"%s\"", path ); -
libtransmission/platform.c
247 247 248 248 if( !home ) 249 249 { 250 home = tr_strdup( getenv( "HOME" ) );250 home = tr_strdup( tr_getenv( "HOME" ) ); 251 251 252 252 if( !home ) 253 253 { 254 254 #ifdef WIN32 255 char appdata[MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */ 255 wchar_t appdataUTF16[MAX_PATH + 1]; 256 char appdata[MAX_PATH + 1]; /* SHGetFolderPath() requires MAX_PATH */ 256 257 *appdata = '\0'; 257 SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, appdata ); 258 SHGetFolderPathW( NULL, CSIDL_PERSONAL, NULL, 0, appdataUTF16 ); 259 WideCharToMultiByte(CP_UTF8, 0, appdataUTF16, -1, appdata, MAX_PATH+1, NULL, NULL); 258 260 home = tr_strdup( appdata ); 259 261 #else 260 262 struct passwd * pw = getpwuid( getuid( ) ); … … 283 285 "Application Support", 284 286 "Transmission", NULL ); 285 287 #elif defined( WIN32 ) 286 char appdata[MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */ 287 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 288 wchar_t appdataUTF16[MAX_PATH + 1]; 289 char appdata[MAX_PATH + 1]; /* SHGetFolderPath() requires MAX_PATH */ 290 SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, 0, appdataUTF16 ); 291 WideCharToMultiByte(CP_UTF8, 0, appdataUTF16, -1, appdata, MAX_PATH+1, NULL, NULL); 288 292 path = tr_buildPath( appdata, "Transmission", NULL ); 289 293 #elif defined( __HAIKU__ ) 290 294 char buf[TR_PATH_MAX]; … … 342 346 { 343 347 if( oldDir && newDir && strcmp( oldDir, newDir ) ) 344 348 { 345 DIR * dirh = opendir( oldDir );349 DIR * dirh = tr_opendir( oldDir ); 346 350 if( dirh ) 347 351 { 348 int 349 struct dirent* dirp;350 while( ( dirp = readdir( dirh ) ) )352 int count = 0; 353 DIRENT * dirp; 354 while( ( dirp = tr_readdir( dirh ) ) ) 351 355 { 356 #ifdef WIN32 357 int n = WideCharToMultiByte(CP_UTF8, 0, dirp->d_name, -1, NULL, 0, NULL, NULL); 358 char name[n]; 359 WideCharToMultiByte(CP_UTF8, 0, dirp->d_name, -1, name, n, NULL, NULL); 360 #else 352 361 const char * name = dirp->d_name; 362 #endif 353 363 if( name && strcmp( name, "." ) && strcmp( name, ".." ) ) 354 364 { 355 365 char * o = tr_buildPath( oldDir, name, NULL ); 356 366 char * n = tr_buildPath( newDir, name, NULL ); 357 rename( o, n );367 tr_rename( o, n ); 358 368 ++count; 359 369 tr_free( n ); 360 370 tr_free( o ); … … 364 374 if( count ) 365 375 tr_inf( _( "Migrated %1$d files from \"%2$s\" to \"%3$s\"" ), 366 376 count, oldDir, newDir ); 367 closedir( dirh );377 tr_closedir( dirh ); 368 378 } 369 379 } 370 380 } … … 442 452 443 453 if( !s ) 444 454 { 445 if( ( s = getenv( "TRANSMISSION_HOME" ) ) )455 if( ( s = tr_getenv( "TRANSMISSION_HOME" ) ) ) 446 456 { 447 457 s = tr_strdup( s ); 448 458 } … … 452 462 s = tr_buildPath( getHomeDir( ), "Library", "Application Support", 453 463 appname, NULL ); 454 464 #elif defined( WIN32 ) 455 char appdata[TR_PATH_MAX]; /* SHGetFolderPath() requires MAX_PATH */ 456 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 465 wchar_t appdataUTF16[MAX_PATH + 1]; 466 char appdata[TR_PATH_MAX + 1]; /* SHGetFolderPath() requires MAX_PATH */ 467 SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, 0, appdataUTF16 ); 468 WideCharToMultiByte(CP_UTF8, 0, appdataUTF16, -1, appdata, MAX_PATH+1, NULL, NULL); 457 469 s = tr_buildPath( appdata, appname, NULL ); 458 470 #elif defined( __HAIKU__ ) 459 471 char buf[TR_PATH_MAX]; 460 472 find_directory( B_USER_SETTINGS_DIRECTORY, -1, true, buf, sizeof(buf) ); 461 473 s = tr_buildPath( buf, appname, NULL ); 462 474 #else 463 if( ( s = getenv( "XDG_CONFIG_HOME" ) ) )475 if( ( s = tr_getenv( "XDG_CONFIG_HOME" ) ) ) 464 476 s = tr_buildPath( s, appname, NULL ); 465 477 else 466 478 s = tr_buildPath( getHomeDir( ), ".config", appname, NULL ); … … 484 496 size_t content_len; 485 497 486 498 /* figure out where to look for user-dirs.dirs */ 487 config_home = getenv( "XDG_CONFIG_HOME" );499 config_home = tr_getenv( "XDG_CONFIG_HOME" ); 488 500 if( config_home && *config_home ) 489 501 config_file = tr_buildPath( config_home, "user-dirs.dirs", NULL ); 490 502 else … … 534 546 static int 535 547 isWebClientDir( const char * path ) 536 548 { 537 struct statsb;549 STAT sb; 538 550 char * tmp = tr_buildPath( path, "index.html", NULL ); 539 const int ret = ! stat( tmp, &sb );551 const int ret = !tr_stati64( tmp, &sb ); 540 552 tr_inf( _( "Searching for web interface file \"%s\"" ), tmp ); 541 553 tr_free( tmp ); 542 554 return ret; … … 549 561 550 562 if( !s ) 551 563 { 552 if( ( s = getenv( "CLUTCH_HOME" ) ) )564 if( ( s = tr_getenv( "CLUTCH_HOME" ) ) ) 553 565 { 554 566 s = tr_strdup( s ); 555 567 } 556 else if( ( s = getenv( "TRANSMISSION_WEB_HOME" ) ) )568 else if( ( s = tr_getenv( "TRANSMISSION_WEB_HOME" ) ) ) 557 569 { 558 570 s = tr_strdup( s ); 559 571 } … … 597 609 #elif defined( WIN32 ) 598 610 599 611 /* SHGetFolderPath explicitly requires MAX_PATH length */ 600 char dir[MAX_PATH]; 612 wchar_t dirUTF16[MAX_PATH + 1]; 613 char dir[MAX_PATH + 1]; 601 614 602 615 /* Generally, Web interface should be stored in a Web subdir of 603 616 * calling executable dir. */ 604 617 605 618 if( s == NULL ) { 606 619 /* First, we should check personal AppData/Transmission/Web */ 607 SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA, NULL, 0, dir ); 620 SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA, NULL, 0, dirUTF16 ); 621 WideCharToMultiByte(CP_UTF8, 0, dirUTF16, -1, dir, MAX_PATH+1, NULL, NULL); 608 622 s = tr_buildPath( dir, "Transmission", "Web", NULL ); 609 623 if( !isWebClientDir( s ) ) { 610 624 tr_free( s ); … … 614 628 615 629 if( s == NULL ) { 616 630 /* check personal AppData */ 617 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, dir ); 631 SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, 0, dirUTF16 ); 632 WideCharToMultiByte(CP_UTF8, 0, dirUTF16, -1, dir, MAX_PATH+1, NULL, NULL); 618 633 s = tr_buildPath( dir, "Transmission", "Web", NULL ); 619 634 if( !isWebClientDir( s ) ) { 620 635 tr_free( s ); … … 624 639 625 640 if( s == NULL) { 626 641 /* check calling module place */ 627 GetModuleFileName( GetModuleHandle( NULL ), dir, sizeof( dir ) ); 642 GetModuleFileNameW( NULL, dirUTF16, sizeof( dirUTF16 ) ); 643 WideCharToMultiByte(CP_UTF8, 0, dirUTF16, -1, dir, MAX_PATH+1, NULL, NULL); 628 644 s = tr_buildPath( dirname( dir ), "Web", NULL ); 629 645 if( !isWebClientDir( s ) ) { 630 646 tr_free( s ); … … 638 654 const char * tmp; 639 655 640 656 /* XDG_DATA_HOME should be the first in the list of candidates */ 641 tmp = getenv( "XDG_DATA_HOME" );657 tmp = tr_getenv( "XDG_DATA_HOME" ); 642 658 if( tmp && *tmp ) 643 659 tr_list_append( &candidates, tr_strdup( tmp ) ); 644 660 else { … … 649 665 /* XDG_DATA_DIRS are the backup directories */ 650 666 { 651 667 const char * pkg = PACKAGE_DATA_DIR; 652 const char * xdg = getenv( "XDG_DATA_DIRS" );668 const char * xdg = tr_getenv( "XDG_DATA_DIRS" ); 653 669 const char * fallback = "/usr/local/share:/usr/share"; 654 670 char * buf = tr_strdup_printf( "%s:%s:%s", (pkg?pkg:""), (xdg?xdg:""), fallback ); 655 671 tmp = buf; … … 697 713 { 698 714 #ifdef WIN32 699 715 uint64_t freeBytesAvailable = 0; 700 return GetDiskFreeSpaceEx( path, &freeBytesAvailable, NULL, NULL) 716 int n = strlen(path) + 1; 717 wchar_t pathUTF16[n]; 718 MultiByteToWideChar(CP_UTF8, 0, path, -1, pathUTF16, n); 719 return GetDiskFreeSpaceExW( pathUTF16, &freeBytesAvailable, NULL, NULL) 701 720 ? (int64_t)freeBytesAvailable 702 721 : -1; 703 722 #elif defined(HAVE_STATVFS) … … 713 732 **** 714 733 ***/ 715 734 735 int tr_open(const char *pathUTF8, int oflag, ...) 736 { 737 va_list a; 738 int mode = 0; 739 va_start(a, oflag); 740 mode = va_arg(a, int); 741 va_end(a); 716 742 #ifdef WIN32 743 if (pathUTF8) { 744 int n = strlen(pathUTF8) + 1; 745 wchar_t pathUTF16[n]; 746 if (MultiByteToWideChar(CP_UTF8, 0, pathUTF8, -1, pathUTF16, n)) 747 /* binary mode is mandatory, otherwise UTF16 data is assumed */ 748 return _wopen(pathUTF16, oflag | _O_BINARY, mode); 749 } 750 errno = ENOENT; 751 return -1; 752 #else 753 return open(pathUTF8, oflag, mode); 754 #endif 755 } 717 756 718 /* The following mmap functions are by Joerg Walter, and were taken from 719 * his paper at: http://www.genesys-e.de/jwalter/mix4win.htm 720 */ 721 722 #if defined(_MSC_VER) 723 __declspec( align( 4 ) ) static LONG volatile g_sl; 757 FILE *tr_fopen(const char *restrict filenameUTF8, const char *restrict mode) 758 { 759 #ifdef WIN32 760 if (filenameUTF8) { 761 int n = strlen(filenameUTF8) + 1; 762 int m = strlen(mode) + 2; 763 wchar_t filenameUTF16[n]; 764 wchar_t modeUTF16[m]; 765 MultiByteToWideChar(CP_UTF8, 0, filenameUTF8, -1, filenameUTF16, n); 766 MultiByteToWideChar(CP_UTF8, 0, mode, -1, modeUTF16, m); 767 /* binary mode is mandatory, otherwise UTF16 data is assumed */ 768 if (!strchr(mode, 'b')) 769 wcscat(modeUTF16, L"b"); 770 return _wfopen(filenameUTF16, modeUTF16); 771 } 772 return NULL; 724 773 #else 725 static LONG volatile g_sl __attribute__ ( ( aligned ( 4 ) ));774 return fopen(filenameUTF8, mode); 726 775 #endif 727 728 /* Wait for spin lock */729 static int730 slwait( LONG volatile *sl )731 {732 while( InterlockedCompareExchange ( sl, 1, 0 ) != 0 )733 Sleep ( 0 );734 735 return 0;736 776 } 737 777 738 /* Release spin lock */ 739 static int 740 slrelease( LONG volatile *sl ) 778 int tr_rename(const char *oldUTF8, const char *newUTF8) 741 779 { 742 InterlockedExchange ( sl, 0 ); 743 return 0; 780 #ifdef WIN32 781 if (oldUTF8 && newUTF8) { 782 int n = strlen(oldUTF8) + 1; 783 int m = strlen(newUTF8) + 1; 784 wchar_t oldUTF16[n]; 785 wchar_t newUTF16[m]; 786 if ( MultiByteToWideChar(CP_UTF8, 0, oldUTF8, -1, oldUTF16, n) && \ 787 MultiByteToWideChar(CP_UTF8, 0, newUTF8, -1, newUTF16, m) ) 788 return MoveFileExW(oldUTF16, newUTF16, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)? 0 : -1; 789 } 790 errno = EINVAL; 791 return -1; 792 #else 793 return rename(oldUTF8, newUTF8); 794 #endif 744 795 } 745 796 746 /* getpagesize for windows */ 747 static long 748 getpagesize( void ) 797 int tr_remove(const char *filenameUTF8) 749 798 { 750 static long g_pagesize = 0; 751 752 if( !g_pagesize ) 799 #ifdef WIN32 800 if (filenameUTF8) 753 801 { 754 SYSTEM_INFO system_info; 755 GetSystemInfo ( &system_info ); 756 g_pagesize = system_info.dwPageSize; 802 int n = strlen(filenameUTF8) + 1; 803 wchar_t filenameUTF16[n]; 804 if ( MultiByteToWideChar(CP_UTF8, 0, filenameUTF8, -1, filenameUTF16, n) ) 805 { 806 int res = _wremove(filenameUTF16); 807 if (res) /* EACCES or ENOENT, might be a directory */ 808 return _wrmdir(filenameUTF16); 809 return res; 810 } 757 811 } 758 return g_pagesize; 812 errno = ENOENT; 813 return -1; 814 #else 815 return remove(filenameUTF8); 816 #endif 759 817 } 760 818 761 static long 762 getregionsize( void ) 819 int tr_unlink(const char *filenameUTF8) 763 820 { 764 static long g_regionsize = 0; 765 766 if( !g_regionsize ) 821 #ifdef WIN32 822 if (filenameUTF8) 767 823 { 768 SYSTEM_INFO system_info; 769 GetSystemInfo ( &system_info ); 770 g_regionsize = system_info.dwAllocationGranularity; 824 int n = strlen(filenameUTF8) + 1; 825 wchar_t filenameUTF16[n]; 826 if ( MultiByteToWideChar(CP_UTF8, 0, filenameUTF8, -1, filenameUTF16, n) ) 827 return _wunlink(filenameUTF16); 771 828 } 772 return g_regionsize; 829 errno = ENOENT; 830 return -1; 831 #else 832 return unlink(filenameUTF8); 833 #endif 773 834 } 774 835 775 void * 776 mmap( void *ptr, 777 long size, 778 long prot, 779 long type, 780 long handle, 781 long arg ) 836 int tr_stati64(const char *restrict pathUTF8, STAT *restrict buf) 782 837 { 783 static long g_pagesize; 784 static long g_regionsize; 785 786 /* Wait for spin lock */ 787 slwait ( &g_sl ); 788 /* First time initialization */ 789 if( !g_pagesize ) 790 g_pagesize = getpagesize ( ); 791 if( !g_regionsize ) 792 g_regionsize = getregionsize ( ); 793 /* Allocate this */ 794 ptr = VirtualAlloc ( ptr, size, 795 MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, 796 PAGE_READWRITE ); 797 if( !ptr ) 798 { 799 ptr = (void *) -1; 800 goto mmap_exit; 838 #ifdef WIN32 839 if (pathUTF8) { 840 int n = strlen(pathUTF8) + 1; 841 wchar_t pathUTF16[n]; 842 if (MultiByteToWideChar(CP_UTF8, 0, pathUTF8, -1, pathUTF16, n)) 843 return _wstati64(pathUTF16, buf); 801 844 } 802 mmap_exit: 803 /* Release spin lock */ 804 slrelease ( &g_sl ); 805 return ptr; 845 errno = ENOENT; 846 return -1; 847 #else 848 return stat(pathUTF8, buf); 849 #endif 806 850 } 807 851 808 long 809 munmap( void *ptr, 810 long size ) 852 DIR *tr_opendir (const char *dirnameUTF8) 811 853 { 812 static long g_pagesize; 813 static long g_regionsize; 814 int rc = -1; 815 816 /* Wait for spin lock */ 817 slwait ( &g_sl ); 818 /* First time initialization */ 819 if( !g_pagesize ) 820 g_pagesize = getpagesize ( ); 821 if( !g_regionsize ) 822 g_regionsize = getregionsize ( ); 823 /* Free this */ 824 if( !VirtualFree ( ptr, 0, 825 MEM_RELEASE ) ) 826 goto munmap_exit; 827 rc = 0; 828 munmap_exit: 829 /* Release spin lock */ 830 slrelease ( &g_sl ); 831 return rc; 854 #ifdef WIN32 855 if (dirnameUTF8) { 856 int n = strlen(dirnameUTF8) + 1; 857 wchar_t dirnameUTF16[n]; 858 if (MultiByteToWideChar(CP_UTF8, 0, dirnameUTF8, -1, dirnameUTF16, n)) 859 return _wopendir(dirnameUTF16); 860 } 861 errno = ENOENT; 862 return NULL; 863 #else 864 return opendir( dirnameUTF8 ); 865 #endif 832 866 } 833 867 868 char *tr_getenv (const char *name) 869 { 870 #ifdef WIN32 871 wchar_t *valueUTF16 = NULL; 872 char *value; 873 int n = strlen(name) + 1; 874 wchar_t nameUTF16[n]; 875 876 if (MultiByteToWideChar(CP_UTF8, 0, name, -1, nameUTF16, n)) 877 valueUTF16= _wgetenv(nameUTF16); 878 if (valueUTF16) 879 { 880 n = WideCharToMultiByte(CP_UTF8, 0, valueUTF16, -1, NULL, 0, NULL, NULL); 881 value = malloc(n); /* leak, could be improved if getenv() returns the same string as the converted one */ 882 WideCharToMultiByte(CP_UTF8, 0, valueUTF16, -1, value, n, NULL, NULL); 883 } 884 else 885 value= NULL; 886 return value; 887 #else 888 return getenv(name); 834 889 #endif 890 } -
libtransmission/platform.h
96 96 /** @brief return nonzero if the specified lock is locked */ 97 97 int tr_lockHave( const tr_lock * ); 98 98 99 /* @} */ 100 101 /** 102 * @addtogroup utf16 Windows_UTF16_Support 103 * @{ 104 */ 105 106 /** 107 * @brief Portability wrapper for open() 108 */ 99 109 #ifdef WIN32 100 void * mmap( void *ptr, long size, long prot, long type, long handle, long arg ); 110 #include <wchar.h> /* _wopen() */ 111 #include <errno.h> /* ENOENT */ 112 #endif 101 113 102 long munmap( void *ptr, long size ); 114 int tr_open(const char *, int, ...); 115 116 /** 117 * @brief Portability wrapper for fopen() 118 */ 119 FILE *tr_fopen(const char *, const char *); 120 121 /** 122 * @brief Portability wrapper for mkdir() 123 * @see tr_mkdir() in utils.c 124 */ 125 126 /** 127 * @brief Portability wrapper for mkstemp() 128 * @see tr_mkstemp() in bencode.c 129 */ 130 131 /** 132 * @brief Portability wrapper for rename() 133 */ 134 int tr_rename(const char *, const char *); 135 136 /** 137 * @brief Portability wrapper for remove() 138 */ 139 int tr_remove(const char *); 140 141 /** 142 * @brief Portability wrapper for unlink() 143 */ 144 int tr_unlink(const char *); 145 146 /** 147 * @brief Portability wrapper for stat() 148 */ 149 #ifdef WIN32 150 #include <sys/stat.h> 151 typedef struct _stati64 STAT; 152 #else 153 typedef struct stat STAT; 103 154 #endif 104 155 156 int tr_stati64(const char *, STAT *); 157 158 /** 159 * @brief Portability wrapper for opendir() 160 */ 161 #ifdef WIN32 162 #include <dirent.h> /* DIR */ 163 #define DIR _WDIR 164 typedef struct _wdirent DIRENT; 165 #define IS_DOT(c) (c == 0x002e) 166 #else 167 typedef struct dirent DIRENT; 168 #define IS_DOT(c) (c == '.') 169 #endif 170 171 DIR *tr_opendir (const char *); 172 173 /** 174 * @brief Portability wrapper for readdir() 175 */ 176 static inline 177 DIRENT *tr_readdir (DIR *dirp) 178 { 179 #ifdef WIN32 180 return _wreaddir(dirp); 181 #else 182 return readdir(dirp); 183 #endif 184 } 185 186 /** 187 * @brief Portability wrapper for closedir() 188 */ 189 static inline 190 int tr_closedir (DIR *dirp) 191 { 192 #ifdef WIN32 193 return _wclosedir(dirp); 194 #else 195 return closedir(dirp); 196 #endif 197 } 198 199 /** 200 * @brief Portability wrapper for getenv() 201 */ 202 char *tr_getenv (const char *); 203 105 204 /* @} */ 106 205 107 206 #endif 207 -
libtransmission/resume.c
898 898 tr_torrentRemoveResume( const tr_torrent * tor ) 899 899 { 900 900 char * filename = getResumeFilename( tor ); 901 unlink( filename );901 tr_unlink( filename ); 902 902 tr_free( filename ); 903 903 } 904 904 -
libtransmission/session.c
1880 1880 int * setmeCount ) 1881 1881 { 1882 1882 int i, n = 0; 1883 struct statsb;1883 STAT sb; 1884 1884 DIR * odir = NULL; 1885 1885 const char * dirname = tr_getTorrentDir( session ); 1886 1886 tr_torrent ** torrents; … … 1890 1890 1891 1891 tr_ctorSetSave( ctor, false ); /* since we already have them */ 1892 1892 1893 if( ! stat( dirname, &sb )1893 if( !tr_stati64( dirname, &sb ) 1894 1894 && S_ISDIR( sb.st_mode ) 1895 && ( ( odir = opendir ( dirname ) ) ) )1895 && ( ( odir = tr_opendir ( dirname ) ) ) ) 1896 1896 { 1897 struct dirent*d;1898 for( d = readdir( odir ); d != NULL; d =readdir( odir ) )1897 DIRENT *d; 1898 for( d = tr_readdir( odir ); d != NULL; d = tr_readdir( odir ) ) 1899 1899 { 1900 if( tr_str_has_suffix( d->d_name, ".torrent" ) ) 1900 #ifdef WIN32 1901 int m = WideCharToMultiByte( CP_UTF8, 0, d->d_name, -1, NULL, 0, NULL, NULL ); 1902 char name[m]; 1903 WideCharToMultiByte( CP_UTF8, 0, d->d_name, -1, name, m, NULL, NULL ); 1904 #else 1905 char * name = d->d_name; 1906 #endif 1907 if( tr_str_has_suffix( name, ".torrent" ) ) 1901 1908 { 1902 1909 tr_torrent * tor; 1903 char * path = tr_buildPath( dirname, d->d_name, NULL );1910 char * path = tr_buildPath( dirname, name, NULL ); 1904 1911 tr_ctorSetMetainfoFromFile( ctor, path ); 1905 1912 if(( tor = tr_torrentNew( ctor, NULL ))) 1906 1913 { … … 1910 1917 tr_free( path ); 1911 1918 } 1912 1919 } 1913 closedir( odir );1920 tr_closedir( odir ); 1914 1921 } 1915 1922 1916 1923 torrents = tr_new( tr_torrent *, n ); … … 2140 2147 { 2141 2148 int binCount = 0; 2142 2149 int newCount = 0; 2143 struct statsb;2150 STAT sb; 2144 2151 char * dirname; 2145 2152 DIR * odir = NULL; 2146 2153 tr_list * list = NULL; … … 2148 2155 2149 2156 /* walk through the directory and find blocklists */ 2150 2157 dirname = tr_buildPath( session->configDir, "blocklists", NULL ); 2151 if( ! stat( dirname,2158 if( !tr_stati64( dirname, 2152 2159 &sb ) && S_ISDIR( sb.st_mode ) 2153 && ( ( odir = opendir( dirname ) ) ) )2160 && ( ( odir = tr_opendir( dirname ) ) ) ) 2154 2161 { 2155 struct dirent*d;2156 for( d = readdir( odir ); d; d =readdir( odir ) )2162 DIRENT *d; 2163 for( d = tr_readdir( odir ); d; d = tr_readdir( odir ) ) 2157 2164 { 2158 2165 char * filename; 2159 2160 if( !d->d_name || d->d_name[0] == '.' ) /* skip dotfiles, ., and .. 2166 #ifdef WIN32 2167 int n = WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, NULL, 0, NULL, NULL); 2168 char name[n]; 2169 WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, name, n, NULL, NULL); 2170 #else 2171 const char * name = d->d_name; 2172 #endif 2173 if( !name || IS_DOT( name[0] ) ) /* skip dotfiles, ., and .. 2161 2174 */ 2162 2175 continue; 2163 2176 2164 filename = tr_buildPath( dirname, d->d_name, NULL );2177 filename = tr_buildPath( dirname, name, NULL ); 2165 2178 2166 2179 if( tr_stringEndsWith( filename, ".bin" ) ) 2167 2180 { … … 2179 2192 /* strip out the file suffix, if there is one, and add ".bin" 2180 2193 instead */ 2181 2194 tr_blocklist * b; 2182 const char * dot = strrchr( d->d_name, '.' );2183 const int len = dot ? dot - d->d_name2184 : (int)strlen( d->d_name );2195 const char * dot = strrchr( name, '.' ); 2196 const int len = dot ? dot - name 2197 : (int)strlen( name ); 2185 2198 char * tmp = tr_strdup_printf( 2186 2199 "%s" TR_PATH_DELIMITER_STR "%*.*s.bin", 2187 dirname, len, len, d->d_name );2200 dirname, len, len, name ); 2188 2201 b = _tr_blocklistNew( tmp, isEnabled ); 2189 2202 _tr_blocklistSetContent( b, filename ); 2190 2203 tr_list_append( &list, b ); … … 2195 2208 tr_free( filename ); 2196 2209 } 2197 2210 2198 closedir( odir );2211 tr_closedir( odir ); 2199 2212 } 2200 2213 2201 2214 session->blocklists = list; … … 2331 2344 static void 2332 2345 metainfoLookupInit( tr_session * session ) 2333 2346 { 2334 struct statsb;2347 STAT sb; 2335 2348 const char * dirname = tr_getTorrentDir( session ); 2336 2349 DIR * odir = NULL; 2337 2350 tr_ctor * ctor = NULL; … … 2345 2358 tr_bencInitDict( lookup, 0 ); 2346 2359 ctor = tr_ctorNew( session ); 2347 2360 tr_ctorSetSave( ctor, false ); /* since we already have them */ 2348 if( ! stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir =opendir( dirname ) ) ) )2361 if( !tr_stati64( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir = tr_opendir( dirname ) ) ) ) 2349 2362 { 2350 struct dirent*d;2351 while(( d = readdir( odir )))2363 DIRENT *d; 2364 while(( d = tr_readdir( odir ))) 2352 2365 { 2353 if( tr_str_has_suffix( d->d_name, ".torrent" ) ) 2366 #ifdef WIN32 2367 int n = WideCharToMultiByte( CP_UTF8, 0, d->d_name, -1, NULL, 0, NULL, NULL ); 2368 char name[n]; 2369 WideCharToMultiByte( CP_UTF8, 0, d->d_name, -1, name, n, NULL, NULL ); 2370 #else 2371 char * name = d->d_name; 2372 #endif 2373 if( tr_str_has_suffix( name, ".torrent" ) ) 2354 2374 { 2355 2375 tr_info inf; 2356 char * path = tr_buildPath( dirname, d->d_name, NULL );2376 char * path = tr_buildPath( dirname, name, NULL ); 2357 2377 tr_ctorSetMetainfoFromFile( ctor, path ); 2358 2378 if( !tr_torrentParse( ctor, &inf ) ) 2359 2379 { … … 2363 2383 tr_free( path ); 2364 2384 } 2365 2385 } 2366 closedir( odir );2386 tr_closedir( odir ); 2367 2387 } 2368 2388 tr_ctorFree( ctor ); 2369 2389 -
libtransmission/makemeta.c
51 51 { 52 52 int i; 53 53 char * buf; 54 struct statsb;54 STAT sb; 55 55 DIR * odir = NULL; 56 56 57 57 sb.st_size = 0; 58 58 59 59 buf = tr_buildPath( dir, base, NULL ); 60 i = stat( buf, &sb );60 i = tr_stati64( buf, &sb ); 61 61 if( i ) 62 62 { 63 63 tr_err( _( "Torrent Creator is skipping file \"%s\": %s" ), … … 66 66 return list; 67 67 } 68 68 69 if( S_ISDIR( sb.st_mode ) && ( ( odir = opendir ( buf ) ) ) )69 if( S_ISDIR( sb.st_mode ) && ( ( odir = tr_opendir ( buf ) ) ) ) 70 70 { 71 struct dirent *d; 72 for( d = readdir( odir ); d != NULL; d = readdir( odir ) ) 73 if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles */ 71 DIRENT *d; 72 for( d = tr_readdir( odir ); d != NULL; d = tr_readdir( odir ) ) 73 if( d->d_name && !IS_DOT( d->d_name[0] ) ) /* skip dotfiles */ 74 { 75 #ifdef WIN32 76 int n = WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, NULL, 0, NULL, NULL); 77 char name[n]; 78 WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, name, n, NULL, NULL); 79 list = getFiles( buf, name, list ); 80 #else 74 81 list = getFiles( buf, d->d_name, list ); 75 closedir( odir ); 82 #endif 83 } 84 tr_closedir( odir ); 76 85 } 77 86 else if( S_ISREG( sb.st_mode ) && ( sb.st_size > 0 ) ) 78 87 { … … 126 135 ret->top = tr_strdup( topFile ); 127 136 128 137 { 129 struct statsb;130 stat( topFile, &sb );138 STAT sb; 139 tr_stati64( topFile, &sb ); 131 140 ret->isSingleFile = !S_ISDIR( sb.st_mode ); 132 141 } 133 142 -
libtransmission/net.c
73 73 { 74 74 *buf = '\0'; 75 75 #ifdef WIN32 76 FormatMessage ( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, buflen, NULL );76 FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, buflen, NULL ); 77 77 #else 78 78 tr_strlcpy( buf, tr_strerror( err ), buflen ); 79 79 #endif -
libtransmission/net.h
38 38 #endif 39 39 40 40 #ifdef WIN32 41 #define ETIMEDOUT WSAETIMEDOUT 41 42 #define EADDRINUSE WSAEADDRINUSE 42 43 #define ECONNREFUSED WSAECONNREFUSED 43 44 #define ECONNRESET WSAECONNRESET -
libtransmission/torrent.c
767 767 768 768 for( i=0; i<n && !has_local_data; ++i ) 769 769 { 770 struct statsb;770 STAT sb; 771 771 char * filename = tr_torrentFindFile( tor, i ); 772 772 773 if( filename && ! stat( filename, &sb ) )773 if( filename && !tr_stati64( filename, &sb ) ) 774 774 has_local_data = true; 775 775 776 776 tr_free( filename ); … … 800 800 uint64_t loaded; 801 801 const char * dir; 802 802 bool isNewTorrent; 803 struct statst;803 STAT st; 804 804 static int nextUniqueId = 1; 805 805 tr_session * session = tr_ctorGetSession( ctor ); 806 806 … … 891 891 } 892 892 893 893 /* if we don't have a local .torrent file already, assume the torrent is new */ 894 isNewTorrent = stat( tor->info.torrent, &st );894 isNewTorrent = tr_stati64( tor->info.torrent, &st ); 895 895 896 896 /* maybe save our own copy of the metainfo */ 897 897 if( tr_ctorGetSave( ctor ) ) … … 1550 1550 1551 1551 for( i=0; i<n; ++i ) 1552 1552 { 1553 struct statsb;1553 STAT sb; 1554 1554 char * filename = tr_torrentFindFile( tor, i ); 1555 1555 1556 1556 sb.st_size = 0; 1557 if( filename && ! stat( filename, &sb ) )1557 if( filename && !tr_stati64( filename, &sb ) ) 1558 1558 byte_count += sb.st_size; 1559 1559 1560 1560 tr_free( filename ); … … 1920 1920 tr_torinf( tor, "Calling script \"%s\"", script ); 1921 1921 1922 1922 #ifdef WIN32 1923 _spawnvpe( _P_NOWAIT, script, (const char* )cmd,env );1923 _spawnvpe( _P_NOWAIT, script, (const char* const *)cmd, (const char* const *)env ); 1924 1924 #else 1925 1925 signal( SIGCHLD, onSigCHLD ); 1926 1926 … … 2380 2380 time_t 2381 2381 tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i ) 2382 2382 { 2383 struct statsb;2383 STAT sb; 2384 2384 time_t mtime = 0; 2385 2385 char * path = tr_torrentFindFile( tor, i ); 2386 2386 2387 if( ( path != NULL ) && ! stat( path, &sb ) && S_ISREG( sb.st_mode ) )2387 if( ( path != NULL ) && !tr_stati64( path, &sb ) && S_ISREG( sb.st_mode ) ) 2388 2388 { 2389 2389 #ifdef SYS_DARWIN 2390 2390 mtime = sb.st_mtimespec.tv_sec; … … 2589 2589 { 2590 2590 if( !tor->info.files[i].dnd ) 2591 2591 { 2592 struct statsb;2592 STAT sb; 2593 2593 const uint64_t length = tor->info.files[i].length; 2594 2594 char * path = tr_torrentFindFile( tor, i ); 2595 2595 2596 2596 bytesLeft += length; 2597 2597 2598 if( ( path != NULL ) && ! stat( path, &sb )2598 if( ( path != NULL ) && !tr_stati64( path, &sb ) 2599 2599 && S_ISREG( sb.st_mode ) 2600 2600 && ( (uint64_t)sb.st_size <= length ) ) 2601 2601 bytesLeft -= sb.st_size; … … 2661 2661 tr_ptrArray * folders, 2662 2662 tr_ptrArray * dirtyFolders ) 2663 2663 { 2664 struct statsb;2664 STAT sb; 2665 2665 char * buf = tr_buildPath( dir, base, NULL ); 2666 int i = stat( buf, &sb );2666 int i = tr_stati64( buf, &sb ); 2667 2667 2668 2668 if( !i ) 2669 2669 { 2670 2670 DIR * odir = NULL; 2671 2671 2672 if( S_ISDIR( sb.st_mode ) && ( ( odir = opendir ( buf ) ) ) )2672 if( S_ISDIR( sb.st_mode ) && ( ( odir = tr_opendir ( buf ) ) ) ) 2673 2673 { 2674 struct dirent*d;2674 DIRENT *d; 2675 2675 tr_ptrArrayInsertSorted( folders, tr_strdup( buf ), vstrcmp ); 2676 for( d = readdir( odir ); d != NULL; d = readdir( odir ) ) 2677 if( d->d_name && strcmp( d->d_name, "." ) && strcmp( d->d_name, ".." ) ) 2676 for( d = tr_readdir( odir ); d != NULL; d = tr_readdir( odir ) ) 2677 if( d->d_name && !IS_DOT( d->d_name[0] ) ) 2678 { 2679 #ifdef WIN32 2680 int n = WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, NULL, 0, NULL, NULL); 2681 char name[n]; 2682 WideCharToMultiByte(CP_UTF8, 0, d->d_name, -1, name, n, NULL, NULL); 2683 walkLocalData( tor, root, buf, name, torrentFiles, folders, dirtyFolders ); 2684 #else 2678 2685 walkLocalData( tor, root, buf, d->d_name, torrentFiles, folders, dirtyFolders ); 2679 closedir( odir ); 2686 #endif 2687 } 2688 tr_closedir( odir ); 2680 2689 } 2681 2690 else if( S_ISREG( sb.st_mode ) && ( sb.st_size > 0 ) ) 2682 2691 { … … 2693 2702 static void 2694 2703 deleteLocalFile( const char * filename, tr_fileFunc fileFunc ) 2695 2704 { 2696 struct statsb;2697 if( ! stat( filename, &sb ) ) /* if file exists... */2705 STAT sb; 2706 if( !tr_stati64( filename, &sb ) ) /* if file exists... */ 2698 2707 fileFunc( filename ); 2699 2708 } 2700 2709 … … 2769 2778 assert( tr_isTorrent( tor ) ); 2770 2779 2771 2780 if( fileFunc == NULL ) 2772 fileFunc = remove;2781 fileFunc = tr_remove; 2773 2782 2774 2783 /* close all the files because we're about to delete them */ 2775 2784 tr_cacheFlushTorrent( tor->session->cache, tor ); … … 2877 2886 { 2878 2887 /* blow away the leftover subdirectories in the old location */ 2879 2888 if( do_move ) 2880 tr_torrentDeleteLocalData( tor, remove );2889 tr_torrentDeleteLocalData( tor, tr_remove ); 2881 2890 2882 2891 /* set the new location and reverify */ 2883 2892 tr_torrentSetDownloadDir( tor, location ); … … 2958 2967 char * oldpath = tr_buildPath( base, sub, NULL ); 2959 2968 char * newpath = tr_buildPath( base, f->name, NULL ); 2960 2969 2961 if( rename( oldpath, newpath ) )2970 if( tr_rename( oldpath, newpath ) ) 2962 2971 tr_torerr( tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) ); 2963 2972 2964 2973 tr_free( newpath ); … … 2976 2985 static bool 2977 2986 fileExists( const char * filename ) 2978 2987 { 2979 struct statsb;2980 const bool ok = ! stat( filename, &sb );2988 STAT sb; 2989 const bool ok = !tr_stati64( filename, &sb ); 2981 2990 return ok; 2982 2991 } 2983 2992 -
qt/qtr.pro
24 24 LIBS += $${TRANSMISSION_TOP}/third-party/miniupnp/libminiupnp.a 25 25 LIBS += $${TRANSMISSION_TOP}/third-party/libnatpmp/libnatpmp.a 26 26 unix: LIBS += -L$${EVENT_TOP}/lib -lz -lrt 27 win32:DEFINES += QT_DBUS 28 win32:LIBS += -levent-2.0 -lws2_32 -lintl 29 win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi 27 win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi -lintl -lpsapi 30 28 31 29 TRANSLATIONS += translations/transmission_en.ts \ 32 30 translations/transmission_es.ts \ -
qt/make-dialog.cc
58 58 { 59 59 case QDialogButtonBox::Open: 60 60 std::cerr << "calling mySession.addTorrent( " << qPrintable(myTarget) << ", " << qPrintable(QFileInfo(myBuilder->top).dir().path()) << ')' << std::endl; 61 mySession.addNewlyCreatedTorrent( myTarget, QFileInfo( myBuilder->top).dir().path() );61 mySession.addNewlyCreatedTorrent( myTarget, QFileInfo(QString::fromUtf8(myBuilder->top)).dir().path() ); 62 62 break; 63 63 case QDialogButtonBox::Abort: 64 64 myBuilder->abortFlag = true; … … 79 79 myNewProgress->setValue( (int) ((100.0 * b->pieceIndex) / denom ) ); 80 80 81 81 // progress label 82 const QString base( QFileInfo( b->top).baseName() );82 const QString base( QFileInfo(QString::fromUtf8(b->top)).completeBaseName() ); 83 83 QString str; 84 84 if( !b->isDone ) 85 85 str = tr( "Creating \"%1\"" ).arg( base ); … … 144 144 myTimer.start( 100 ); 145 145 146 146 // the file to create 147 myTarget = QDir( myDestination ).filePath( QFileInfo( myBuilder->top).baseName() + ".torrent" );147 myTarget = QDir( myDestination ).filePath( QFileInfo(QString::fromUtf8(myBuilder->top)).completeBaseName() + ".torrent" ); 148 148 std::cerr << qPrintable(myTarget) << std::endl; 149 149 150 150 // comment -
qt/session.cc
44 44 #include "prefs.h" 45 45 #include "session.h" 46 46 #include "session-dialog.h" 47 48 #ifdef WIN32 49 #undef ERROR /* defined in wingdi.h, included by windows.h */ 50 #endif 51 47 52 #include "torrent.h" 48 53 #include "utils.h" 49 54 -
third-party/dht/dht.c
83 83 { 84 84 return rand(); 85 85 } 86 extern const char *inet_ntop(int, const void *, char *, socklen_t); 86 extern const char *evutil_inet_ntop(int, const void *, char *, socklen_t); 87 #define inet_ntop(a,b,c,d) evutil_inet_ntop(a,b,c,d) 87 88 88 89 #else 89 90 -
third-party/libutp/utp.cpp
12 12 #include <limits.h> // for UINT_MAX 13 13 14 14 #ifdef WIN32 15 #include "win32_inet_ntop.h" 15 /* libtransmission switched to using libevent's inet_ntop */ 16 extern const char *evutil_inet_ntop(int, const void *, char *, socklen_t); 17 #define inet_ntop(a,b,c,d) evutil_inet_ntop(a,b,c,d) 16 18 17 19 // newer versions of MSVC define these in errno.h 18 20 #ifndef ECONNRESET